Java 7 Date Time Formatting
OVerview Patterns Java 7 Date Time Examples
Overview
Java 7 SimpleDateFormat allows you to define patterns for date and time formatting to manipulate the display of the data. If you are looking to format datetime in Android or Kotlin, please check out our page dedicated to Kotlin Date Time Formatting. Further documentation for the SimpleDateFormat Java SE 7 class can be found in the link below.
https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html
Patterns
Letter | Date or Time Component | Presentation | Examples |
---|---|---|---|
G |
Era designator | Text | AD |
y |
Year | Year | 1996 ; 96 |
Y |
Week year | Year | 2009 ; 09 |
M |
Month in year | Month | July ; Jul ; 07 |
w |
Week in year | Number | 27 |
W |
Week in month | Number | 2 |
D |
Day in year | Number | 189 |
d |
Day in month | Number | 10 |
F |
Day of week in month | Number | 2 |
E |
Day name in week | Text | Tuesday ; Tue |
u |
Day number of week (1 = Monday, …, 7 = Sunday) | Number | 1 |
a |
Am/pm marker | Text | PM |
H |
Hour in day (0-23) | Number | 0 |
k |
Hour in day (1-24) | Number | 24 |
K |
Hour in am/pm (0-11) | Number | 0 |
h |
Hour in am/pm (1-12) | Number | 12 |
m |
Minute in hour | Number | 30 |
s |
Second in minute | Number | 55 |
S |
Millisecond | Number | 978 |
z |
Time zone | General time zone | Pacific Standard Time ; PST ; GMT-08:00 |
Z |
Time zone | RFC 822 time zone | -0800 |
X |
Time zone | ISO 8601 time zone | -08 ; -0800 ; -08:00 |
Java 7 Date Time Examples
Date and Time Pattern | Result |
---|---|
"yyyy.MM.dd G 'at' HH:mm:ss z" |
2018.01.04 AD at 10:19:47 PDT |
"EEE, MMM d, ''yy" |
Fri, Feb 4, '18 |
"h:mm a" |
10:45 PM |
"hh 'o''clock' a, zzzz" |
10 o'clock AM, Pacific Daylight Time |
"K:mm a, z" |
0:02 AM, PDT |
"yyyyy.MMMMM.dd GGG hh:mm aaa" |
02018.January.04 AD 10:45 PM |
"EEE, d MMM yyyy HH:mm:ss Z" |
Tue, 12 May 2018 11:34:19 -0700 |
"yyMMddHHmmssZ" |
011304220856-0700 |
"yyyy-MM-dd'T'HH:mm:ss.SSSZ" |
2018-11-07T11:19:24.123-0200 |
"yyyy-MM-dd'T'HH:mm:ss.SSSXXX" |
2018-11-07T11:19:24.123-02:00 |
"YYYY-'W'ww-u" |
2018-W27-3 |