Guestbook 
 Freebok   Guestbook   Home   
 Login 
Sitemap 
|  Site  |  Users  |  Help  | 
  

Date format strings

SymbolMeaningPresentationExample
Gera designator(Text)AD
yyear(Number)1996
Mmonth in year(Text & Number)July & 07
dday in month(Number)10
hhour in am/pm (1~12)(Number)12
Hhour in day (0~23)(Number)0
mminute in hour(Number)30
ssecond in minute(Number)55
Smillisecond(Number)978
Eday in week(Text)Tuesday
Dday in year(Number)189
Fday of week in month(Number)2 (2nd Wed in July)
wweek in year(Number)27
Wweek in month(Number)2
aam/pm marker(Text)PM
khour in day (1~24)(Number)24
Khour in am/pm (0~11)(Number)0
ztime zone(Text)Pacific Standard Time
'escape for text(Delimiter) 
''single quote(Literal)'

The count of pattern letters determines the format.

(Text): 4 or more pattern letters--use full form, < 4--use short or abbreviated form if one exists.

(Number): the minimum number of digits. Shorter numbers are zero-padded to this amount. Year is handled specially; that is, if the count of 'y' is 2, the Year will be truncated to 2 digits.

(Text & Number): 3 or over, use text, otherwise use number.

Any characters in the pattern that are not in the ranges of ['a'..'z'] and ['A'..'Z'] will be treated as quoted text. For instance, characters like ':', '.', ' ', '#' and '@' will appear in the resulting time text even they are not embraced within single quotes.

A pattern containing any invalid pattern letter will result in a thrown exception during formatting or parsing.

Examples Using the US Locale:

Format PatternResult
yyyy.MM.dd G 'at' hh:mm:ss z1996.07.10 AD at 15:08:56 PDT
EEE, MMM d, 'yyWed, July 10, '96
h:mm a12:08 PM
hh 'o''clock' a, zzzz12 o'clock PM, Pacific Daylight Time
K:mm a, z0:00 PM, PST
yyyyy.MMMMM.dd GGG hh:mm aaa1996.July.10 AD 12:08 PM

This information and the examples have been taken from the Java 2 Platform Std. Ed. v1.3.1 documentation. (c) Sun Microsystems.