For more information about the internal values of these variables, see "Primitive data types."
The default mask is yyyyMM.
yyyyyyMM yyyyyy MM ddHHmmssffffff HHmmssff mmss HHmm
// NOT valid ddmmssffffff HHssff
The default mask is yyyyMMddHHmmss.
yyyyMMddHHmmss yyyy MMss
// NOT valid ddMMssffffff HHssff
The rules for a parsing format are similar to those for a display format, with exceptions noted in the following rules.
Create your own format pattern by using letters to indicate the components of the date or time. To include letters in the date/time string without that text being parsed as a component of the date or time, enclose that letter or letters in single quotation marks. To display a single quotation mark in the date, time, or timestamp, use two single quotation marks.
The following table lists the letters and their values in the 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 in week | Number | 2 |
E | Day of 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 (output) | Number | 978 |
f | Millisecond (parsing) | 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 |
Multiples of the same letter used consecutively in the pattern determine how EGL parses the corresponding numbers, letters, or both in the string. The interpretation depends on the type of letter, and on whether the pattern is being used for formatting or parsing. The following list describes the types of letters and how different quantities of those letters affect the way they are interpreted.
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 2007, 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.
t TIMESTAMP( "ssffff" ); s STRING = StrLib.formatTimestamp( t, "ssSSSS" );
GMTOffsetTimeZone = GMT Sign Hours Minutes
For parsing, RFC 822 time zones are also accepted.
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.
The following table lists some examples of date and time patterns interpreted in the U.S. locale. All use the same date: 4 July, 2001, 12:08:56 in the afternoon, Pacific Daylight Time.
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 |
The date/time format specifiers can also include calendar specifiers. These specifiers indicate a calendar system that EGL uses to parse a date string for input, or format a date string for output. EGL performs a conversion between the string date for a specified calendar and the internal value of the DATE, TIME, or TIMESTAMP variable.
Calendar specifier | Calendar |
---|---|
Bu | Buddhist |
Ch | Chinese |
Gr | Gregorian |
He | Hebrew |
Is | Islamic |
Ja | Japanese |
This subject becomes complex quickly because localized date strings in the various calendar systems might not be printable in other locales. Different calendars use different starting points for numbering years, as well as different era designators, many of which display properly only in specific localized environments. For example, the Japanese Imperial date system ties dates to the reigns of Japanese emperors as well as to the old-style Julian Calendar (which is several days behind the Gregorian).
myDate DATE; myJapaneseDate STRING; strLib.defaultDateFormat = "Gryyyy/MM/dd"; myDate = "1912/08/13"; myJapaneseDate = formatDate(myDate,"JaGyy/MM/dd");If your system is localized for Japan, you can set strLib.defaultDateFormat to use the Japanese calendar and set myDate to a Japanese calendar date. EGL parses the date string according to the default date format and stores it as an eight-digit Gregorian date.
The following table lists sample Gregorian dates as converted to the Japanese era format specified above. The names in brackets represent the four double-byte Japanese characters for a specific Japanese era.
Gregorian Date | Japanese Era-based Date |
---|---|
1868/09/20 | [Meiji]01/09/08 |
1912/08/12 | [Meiji]45/07/30 |
1912/08/13 | [TaishÅ?]01/07/31 |
1927/01/07 | [TaishÅ?]15/12/25 |
1927/01/08 | [ShÅ?wa]01/12/26 |
1989/01/20 | [ShÅ?wa]64/01/07 |
1989/01/21 | [Heisei]01/01/08 |
2005/01/14 | [Heisei]17/01/01 |
EGL uses the Java™ version of the International Components for Unicode libraries (ICU4J) to perform the necessary date conversions for input and display. However, EGL always stores the dates in Gregorian form using eight digits. This means that if a Thai application requests a date from the Buddhist calendar, EGL stores that date in eight-digit Gregorian form using ICU4J for the conversion. As long as the application is consistent in the patterns it uses, this process remains invisible to both the programmer and the user.
Platform | Issue |
---|---|
COBOL generation |
|
DB2® | See "COBOL generation" entry in this table. |
Rich UI | See Rich UI date and time support. |