본문 바로가기
프로그래밍

Date/Time Format Syntax

by 백룡화검 2013. 7. 18.


출처 : http://userguide.icu-project.org/formatparse/datetime



Date/Time Format Syntax

A date pattern is a string of characters, where specific strings of characters are replaced with date and time data from a calendar when formatting or used to generate data for a calendar when parsing.

The Date Field Symbol Table below contains the characters used in patterns to show the appropriate formats for a given locale, such as yyyy for the year. Characters may be used multiple times. For example, if y is used for the year, 'yy' might produce '99', whereas 'yyyy' produces '1999'. For most numerical fields, the number of characters specifies the field width. For example, if h is the hour, 'h' might produce '5', but 'hh' produces '05'. For some characters, the count specifies whether an abbreviated or full form should be used, but may have other choices, as given below.

Two single quotes represents a literal single quote, either inside or outside single quotes. Text within single quotes is not interpreted in any way (except for two adjacent single quotes). Otherwise all ASCII letter from a to z and A to Z are reserved as syntax characters, and require quoting if they are to represent literal characters. In addition, certain ASCII punctuation characters may become variable in the future (eg ":" being interpreted as the time separator and '/' as a date separator, and replaced by respective locale-sensitive characters in display).

"Stand Alone" values refer to those designed to stand on their own, as opposed to being with other formatted values. "2nd quarter" would use the stand alone format (QQQQ), whereas "2nd quarter 2007" would use the regular format (qqqq yyyy).

Symbol Meaning Example
G era designator G AD
y year yy
yyyy or y
96
1996
Y year of "Week of Year" Y 1997
u extended year u 4601
U cyclic year name, as in Chinese lunar calendar U 甲子
Q quarter Q or QQ
QQQ
QQQQ
02
Q2
2nd quarter
q Stand Alone quarter q or qq
qqq
qqqq
02
Q2
2nd quarter
M month in year M or MM
MMM
MMMM
MMMMM
09
Sept
September
S
L Stand Alone month in year L or LL
LLL
LLLL
LLLLL
09
Sept
September
S
w week of year w or ww 27
W week of month W 2
d day in month d
dd
2
02
D day of year D 189
F day of week in month
2 (2nd Wed in July)
g modified julian day g 2451334
E day of week E, EE, or EEE
EEEE
EEEEE
Tues
Tuesday
T
e local day of week
example: if Monday is 1st day, Tuesday is 2nd )
e or ee
eee
eeee
eeeee
2
Tues
Tuesday
T
c Stand Alone local day of week e or ee
eee
eeee
eeeee
2
Tues
Tuesday
T
a am/pm marker a pm
h hour in am/pm (1~12) h
hh
7
07
H hour in day (0~23) H
HH
0
00
k hour in day (1~24) k
kk
24
24
K hour in am/pm (0~11) K
KK
0
00
m minute in hour m
mm
4
04
s second in minute s
ss
5
05
S millisecond (maximum of 3 significant digits);
for S or SS, truncates to the number of letters

for SSSS or longer, fills additional places with 0
S
SS
SSS
SSSS
2
23
235
2350
A milliseconds in day A 61201235
z Time Zone: specific non-location z, zz, or zzz
zzzz
PDT
Pacific Daylight Time
Z Time Zone: RFC 822
Time Zone: localized GMT
TIme Zone: ISO8601
Z, ZZ, or ZZZ
ZZZZ
ZZZZZ
-0800
GMT-08:00
-08:00
v Time Zone: generic non-location v
vvvv
PT
Pacific Time or United States (Los Angeles)
V Time Zone: specific non-location, identical to z V PDT
VVVV Time Zone: generic location VVVV United States (Los Angeles)
W week in month
2
' escape for text ' (nothing)
' ' two single quotes produce one ' ' '
Note 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 enclosed within single quotes.The single quote is used to 'escape' letters. Two single quotes in a row, whether inside or outside a quoted sequence, represent a 'real' single quote.

A pattern containing any invalid pattern letter results in a failing UErrorCode result during formatting or parsing.
Format Pattern Result

yyyy.MM.dd G 'at' HH:mm:ss zzz

1996.07.10 AD at 15:08:56 PDT

EEE, MMM d, ''yy

Wed, July 10, '96

h:mm a

12:08 PM

hh 'o''clock' a, zzzz

12 o'clock PM, Pacific Daylight Time

K:mm a, z

0:00 PM, PST

yyyyy.MMMM.dd GGG hh:mm aaa

01996.July.10 AD 12:08 PM

Time Zone Display Names

ICU supports time zone display names defined by the LDML (Unicode Locale Data Markup Language ) specification. Since ICU 3.8, the vast majority of localized time zone names are no longer associated with individual time zones. Instead, a set of localized time zone names are associated with a metazone and one or more individual time zones are mapped to the same metazone. For example, metazone “America_Pacific” has its own display name data such as “PST” “PDT” “PT” “Pacific Standard Time” “Pacific Daylight Time” “Pacific Time” and these names are shared by multiple individual time zones “America/Los_Angeles”, “America/Vancouver”, “America/Tijuana” and so on. The mapping from individual time zone to metazone is not a simple 1-to-1 mapping, but it changes time to time. For example, time zone “America/Indiana/Tell_City” uses name data from metazone “America_Eastern” until April 2, 2006, but it   changes to metazone “America_Central” after the date. So the display name used for “America/Indiana/Tell_City” before the date (e.g. “Eastern Time”) differs from the one after the date (e.g. “Central Time).

Note Prior to ICU 3.8, a localized time zone name (except GMT format) and a time zone ID was in 1-to-1 relationship always. Therefore, a time zone name produced by DateFormat can be parsed back to the original time zone. This assumption no longer applies to ICU 3.8 and later releases for all time zone format types. If you program requires to roundtrip specific time zone ID, you must use the generic location format (“VVVV”) explained below.

There are several different display name types available in the LDML specification.

Type Description Examples
Generic non-location Reflects wall time, suited for displaying recurring events, meetings or anywhere people do not want to be overly specific. Available in two length options – long and short. Pacific TimePT
Generic partial location Reflects wall time, used as a fallback format when the generic non-location format is not specific enough. A generic partial location name is constructed from a generic non-location name with a location name. For example, “PT” is shared by multiple time zones via metazone “America_Pacific”. When GMT offset in the time zone at the given time differs from the preferred time zone of the metazone for the locale, location name is appended to generic non-location name to distinguish the time zone from the preferred zone. Available in two length options – long and short. Pacific Time (Canada)PT (Yellowknife)
Generic location Reflects wall time, suited for populating choice list for time zones. If the time zone is the single time zone available in the region (country), the generic location name is constructed with the region name. Otherwise, the name is constructed from the region name and the city name. Unlike other format types, this name is unique per time zone. United States (Los Angeles) TimeItaly Time
Specific non-location Reflects a specific standard or daylight time. Available in two length options – long and short. Pacific Standard TimePDT
Localized GMT A constant, specific offset from GMT in a localized form. GMT-08:00
RFC822 GMT A constant, specific offset from GMT in a locale insensitive format. -0800

Each format type in the above table is used as a primary type or a fallback in SimpleDateFormat. The table below explains how ICU time zone format pattern work and its characteristics.

Pattern Behavior Round-trip time at daylight transitions(*) Round-trip Time Zone Suggested Usage
z, zz, zzz Short specific non-location format (e.g. “PST”).If the localized data is not available or the short abbreviation is not commonly used for the locale, localized GMT format is used (e.g. GMT-08:00). yes no For displaying a time with a user friendly time zone name.
zzzz Long specific non-location format (e.g. “Pacific Standard Time”).If the localized data is not available, localized GMT format is used (e.g. GMT-08:00). yes no Same as “z”, but longer format.
v Short generic non-location format (e.g. “PT”).If the localized data is not available or the short abbreviation is not commonly used for the locale, generic location format (e.g. “United States(Los Angeles) Time”) is used.If the localized data comes from metazone and the GMT offset at the given time in the specified time zone differs from the preferred time zone of the metazone for the locale, generic partial location format (e.g. “PT (Canada)”) is used. no no For displaying a recurring wall time (e.g. events, meetings) or anywhere people do not want to be overly specific.
vvvv Long generic non-location format (e.g. “Pacific Time”).If the localized data is not available, generic location format (e.g. “United States(Los Angeles) Time”) is used. no no Same as “v”, but longer format.
V Same as “z”, except using the short abbreviation even it is not commonly used for the locale. yes no Same as “z”.
VVVV Generic location format (e.g. “United States (Los Angeles) Time”). no yes For populating a choice list for time zones, because it supports 1-to-1 name/zone ID mapping and is more uniform than other text formats.Also, this is only the pattern supporting time zone round-trip. If your program requires to preserve the original time zone information, use this pattern.
Z, ZZ, ZZZ Localized GMT format (e.g. “GMT-08:00”). yes no For displaying a time in UI in a uniformed manner.
ZZZZ RFC822 GMT format (e.g. “-0800”). yes no For formatting a time for non-user-facing data.

* At a transition from daylight saving time to standard time, there is a wall time interval occurs twice.

DateFormatSymbols

DateFormatSymbols is a public class for encapsulating localizable date-time formatting data, including time zone data. DateFormatSymbols is used by DateFormat and SimpleDateFormat.

DateFormatSymbols specifies the exact character strings to use for various parts of a date or time For example, the names of the months and days of the week, the strings for AM and PM and the day of the week considered to be the first day of the week (used in drawing calendar grids) are controlled by DateFormatSymbols.

Create a date-time formatter using the createTimeInstance, createDateInstance, or createDateTimeInstance methods in DateFormat. Each of these methods can return a date/time formatter initialized with a default format pattern, along with the date-time formatting data for a given or default locale. After a formatter is created, modify the format pattern using applyPattern.

If you want to create a date-time formatter with a particular format pattern and locale, use one of the SimpleDateFormat constructors:

UnicodeString aPattern("GyyyyMMddHHmmssSSZ", "");
new SimpleDateFormat(aPattern, new DateFormatSymbols(Locale::getUS())


'프로그래밍' 카테고리의 다른 글

환율API 이용하기  (0) 2011.01.05
Flex, Air, WPF, Silverlight  (0) 2009.06.13