Sunday, December 11, 2011

Java SimpleDateFormatter string formats

SimpleDateFormat is a concrete class for formatting and parsing dates in a locale-sensitive manner. It allows for formatting (date -> text), parsing (text -> date), and normalization.

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.





SymbolMeaningTypeExample
GEraText“GG” -> “AD”
yYearNumber“yy” -> “03″
“yyyy” -> “2003″
MMonthText or Number“M” -> “7″
“M” -> “12″
“MM” -> “07″
“MMM” -> “Jul”
“MMMM” -> “December”
dDay in monthNumber“d” -> “3″
“dd” -> “03″
hHour (1-12, AM/PM)Number“h” -> “3″
“hh” -> “03″
HHour (0-23)Number“H” -> “15″
“HH” -> “15″
kHour (1-24)Number“k” -> “3″
“kk” -> “03″
KHour (0-11 AM/PM)Number“K” -> “15″
“KK” -> “15″
mMinuteNumber“m” -> “7″
“m” -> “15″
“mm” -> “15″
sSecondNumber“s” -> “15″
“ss” -> “15″
SMillisecond (0-999)Number“SSS” -> “007″
EDay in weekText“EEE” -> “Tue”
“EEEE” -> “Tuesday”
DDay in year (1-365 or 1-364)Number“D” -> “65″
“DDD” -> “065″
FDay of week in month (1-5)Number“F” -> “1″
wWeek in year (1-53)Number“w” -> “7″
WWeek in month (1-5)Number“W” -> “3″
aAM/PMText“a” -> “AM”
“aa” -> “AM”
zTime zoneText“z” -> “EST”
“zzz” -> “EST”
“zzzz” -> “Eastern Standard Time”
Excape for textDelimiter“‘hour’ h” -> “hour 9″
Single quoteLiteral“ss”SSS” -> “45’876″


No comments: