Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Java defines a class (java.text.SimpleDateFormat) that provides a convenient way to convert strings with date and/or time information so that it appears in your desired format.

Date and Time Patterns

Date and time formats are specified by date and time pattern strings. Within date and time pattern strings, unquoted letters from 'A' to 'Z' and from 'a' to 'z' are interpreted as pattern letters representing the components of a date or time string. Text can be quoted using single quotes (') to avoid interpretation. "''" represents a single quote. All other characters are not interpreted; they're simply copied into the output string during formatting or matched against the input string during parsing.

...

Table plus
highlightColor#ffffec
rowStylesbackground:#f0f0f0;color:#222;font-size:14px;border-bottom:black 2px solid;border-top:black 2px solid;,
stylebackground-color:white;
autoNumbertrue
LetterDate or Time ComponentExamples
GEra designator GG → AD 
Year 

"yy" → 14

 "yyyy"2014

Month in year 

"M" → 3

"MM" → 03

"MMM" → Mar

"MMMM" → March

Week in year "w" → 09 
Week in month "W" → 1
D Day in year

"D" → 60

"DDD" → 060

dDay in month 

"d" 1

"dd" → 01

Day of week in month "F"
Day in week 

"EEE" → Sat

 "EEEE"Saturday

Am/pm marker 

"a"PM

"aa"

Hour in day (0-23) 

"H" → 8 

"HH" → 08

Hour in day (1-24) 

"k" → 8

"kk" → 08

Hour in am/pm (0-11 AM/PM) 

"K" → 8

 "KK" → 08 

Hour in am/pm (1-12, AM/PM)

"h" → 8

 "hh" → 08 

Minute in hour 

"m" → 6 

"mm" → 06

Second in minute 

"s" → 5

 "ss" → 05 

 SMillsecond (0-999)"SSS"978 
Time zone 

"z" → EST

"zz" → EST

"zzzz" → Eastern Standard Time 

ZTime zone-0800

 

Examples

The following examples show how date and time patterns are interpreted in the U.S. locale. The given date and time are 2001-07-04 12:08:56 local time in the U.S. Pacific Time time zone.  

...