Formatting dates and times

Date and time formats are specified by date and time pattern strings. Within date and time pattern strings, letters from 'A' to 'Z' and from 'a' to 'z' are interpreted as pattern letters representing the components of a date or time string. The number of pattern letters repeated determines the presentation.

Text can be quoted using single quotes (') to avoid interpretation. To represent a single quote, use two single quotes ('').All other characters are copied into the output string during formatting or matched against the input string during parsing; they are not interpreted.

The following pattern letters are defined (all other characters from 'A' to 'Z' and from 'a' to 'z' are reserved):

Letter

Date/Time Component

Formatting

Examples

G

Era

If there are four or more pattern letters, the full form is used; otherwise an abbreviated form is used if available.

AD

y

Year

If there are two pattern letters, the year is truncated to two digits; otherwise it is interpreted as a number.

2008; 08

M

Month or month in year

If there are three or more pattern letters, the month is interpreted as text; otherwise, it is interpreted as a number.

February; Feb; 02

w

Week in year

The number of pattern letters is the minimum number of digits, and shorter numbers are zero-padded to this amount.

36

W

Week in month

The number of pattern letters is the minimum number of digits, and shorter numbers are zero-padded to this amount.

2

D

Day in year

The number of pattern letters is the minimum number of digits, and shorter numbers are zero-padded to this amount.

172

d

Day in month

The number of pattern letters is the minimum number of digits, and shorter numbers are zero-padded to this amount.

28

F

Day of week in month

The number of pattern letters is the minimum number of digits, and shorter numbers are zero-padded to this amount.

2

E

Day in week

If there are four or more pattern letters, the full form is used; otherwise an abbreviated form is used if available.

Thursday; Thu

a

AM/PM

If there are two pattern letters, the full form is used; otherwise an abbreviated form is used if available.

PM

H

Hour in day (0-23)

The number of pattern letters is the minimum number of digits, and shorter numbers are zero-padded to this amount.

0

k

Hour in day (1-24)

The number of pattern letters is the minimum number of digits, and shorter numbers are zero-padded to this amount.

24

K

Hour in AM/PM (0-11)

The number of pattern letters is the minimum number of digits, and shorter numbers are zero-padded to this amount.

0

h

Hour in AM/PM (1-12)

The number of pattern letters is the minimum number of digits, and shorter numbers are zero-padded to this amount.

12

m

Minute in hour

The number of pattern letters is the minimum number of digits, and shorter numbers are zero-padded to this amount.

35

s

Second in minute

The number of pattern letters is the minimum number of digits, and shorter numbers are zero-padded to this amount.

55

S

Millisecond

The number of pattern letters is the minimum number of digits, and shorter numbers are zero-padded to this amount.

798

z

Time zone

Time zones are interpreted as text if they have names. For time zones representing a GMT offset value, the following syntax is used:

GMT<sign><hours>:<minutes>

 

<sign>: must be one of '+' or '-'

<hours>: must be between 0 and 23

<minutes>: must be between 00 and 59.

Eastern Standard Time; EST; GMT-05:00

Z

Time zone

For RFC 822 4-digit time zone formats, the following syntax is used:

<sign><twoDigitHours><minutes>

 

<sign>: must be one of '+' or '-'

<twoDigitHours>: must be between 00 and 23

<minutes>: must be between 00 and 59.

-0500

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:

Date/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

"yyyy-MM-dd'T'HH:mm:ss.SSSZ"

2001-07-04T12:08:56.235-0700

Format Statement

@script::formatDate

@script::formatDateValue