Date, time, and timestamp format specifiers

The formats of dates, times, and timestamps are specified by a pattern of letters, each representing a component of the date or time. These characters are case-sensitive, and all letters from a to z and from A to Z parse to a component of the date or time.

To display letters in the date, time, or timestamp without that text being parsed as a component of the date or time, enclose that letter or letters in single quotes. To display a single quote in the date, time, or timestamp, use two single quotes.

The following table lists the letters and their values in a date, time, or timestamp pattern.

Letter Date or time component Type Examples
G Era designator Text AD
y Year Year 1996; 96
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 in week Text Tuesday; Tue
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 -800
C Century Century 20; 21

The number of each letter used consecutively in the pattern determines how that group of letters is interpreted and parsed. The interpretation depends on the type of letter. Also, the interpretation depends on whether the pattern is being used for formatting or parsing. The following list describes the types of letters and how different numbers of those letters affect the interpretation.

Text
For formatting, if the number of letters is less than 4, the full form is used. Otherwise, an abbreviation is used, if available. In parsing, both forms are accepted, independent of the number of pattern letters.
Number
For formatting, the number of pattern letters represents the minimum number of digits. Zeroes are added to shorter numbers to make them the designated length. For parsing, the number of pattern letters is ignored unless it is needed to separate two adjacent fields.
Year
For formatting, if the number of pattern letters is 2, the year is truncated to 2 digits. Otherwise, it is interpreted as the Number type.

For parsing, if the number of pattern letters is not 2, the year is interpreted literally, regardless of the number of digits. For example, the pattern MM/dd/yyyy assigned the value 01/11/12 parses to January 11, 12 A.D. The same pattern assigned the value 01/02/3 or 01/02/0003 parses to January 2, 3 A.D. In the same way, the same pattern assigned the value 01/02/-3 parses to January 2, 4 B.C.

For parsing, if the pattern is yy, the parser determines the full year relative to the current year. The parser assumes that the two-digit year is within 80 years before or 20 years after the time of processing. For example, if the current year is 2004, the pattern MM/dd/yy assigned the value 01/11/12 parses to January 11, 2012, while the same pattern assigned the value 05/04/64 parses to May 4, 1964.

Month
If the number of pattern letters is 3 or more, the month is interpreted as the Text type. Otherwise, it is interpreted as the Number type.
General time zone
General time zones are interpreted as the Text type if they have names. For time zones representing a GMT offset value, the following syntax is used:

GMTOffsetTimeZone = GMT Sign Hours : Minutes

Sign
Either + or -
Hours
A one-digit or two-digit number from 0 to 23. The format is locale independent and must be taken from the Basic Latin block of the Unicode standard.
Minutes
A two-digit number from 00 to 59. The format is locale independent and must be taken from the Basic Latin block of the Unicode standard.

For parsing, RFC 822 time zones are also accepted.

RFC 822 time zone
For formatting, the RFC 822 4-digit time zone format is used

RFC822TimeZone = Sign TwoDigitHours : Minutes

TwoDigitHours must be a two-digit number from 00 to 23. The other definitions are the same as the General time zone type.

For parsing, General time zones are also accepted.

Century
Displayed as a Number type that shows the result of the following calculation: full year divided by 100, with the remainder ignored.

The following table lists some examples of date and time patterns interpreted in the U.S. locale.

Date and Time Pattern Result
yyyy.MM.dd G 'at' HH:mm:ss z 2001.07.04 AD at 12:08:56 PDT
EEE, MMM d, ''yy Wed, Jul 4, '01
h:mm a 12:08 PM
hh 'o''clock' a, zzzz 12 o'clock PM, Pacific Daylight Time
K:mm a, z 0:08 PM, PDT
yyyyy.MMMMM.dd GGG hh:mm aaa 02001.July.04 AD 12:08 PM
EEE, d MMM yyyy HH:mm:ss Z Wed, 4 Jul 2001 12:08:56 -0700
yyMMddHHmmssZ 010704120856-0700
Feedback
(C) Copyright IBM Corporation 2000, 2005. All Rights Reserved.