Formatting and parsing date-time patterns

For some fields in HCL OneTest API, you can define patterns for date-time formatting. Pattern letters are repeated, as their number determines the exact presentation of the date-time information that they represent.

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 'a' to 'z' are interpreted as pattern letters that represent the components of a date or time string. Text can be quoted by using single quotation marks (') to avoid interpretation. "''" represents a single quotation mark. All other characters are not interpreted; they are simply copied into the output string during formatting or matched against the input string during parsing. The following pattern letters are defined (all other characters from 'A' to 'Z' and from 'a' to 'z' are reserved):

Letter Date or Time Component Presentation 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 -0800
See these sections for more information about how the various pattern types are formatted and parsed in HCL OneTest API.

Text

For formatting, if the number of pattern letters is four or more, the full form is used. Otherwise, a short or abbreviated form is used if available. For parsing, both forms are accepted, independent of the number of pattern letters.

Number

For formatting, the number of pattern letters is the minimum number of digits, and shorter numbers are zero-padded to this amount. For parsing, the number of pattern letters is ignored unless it is needed to separate two adjacent fields.

Year

For formatting, if two pattern letters are used, the year is truncated to two digits. Otherwise, the year is interpreted as a number.

For parsing, if the number of pattern letters is more than two, the year is interpreted literally, regardless of the number of digits. For example, the pattern "MM/dd/yyyy", "01/11/12" parses to Jan 11, 12 A.D.

For parsing with the abbreviated year pattern ("y" or "yy"), HCL OneTest API interprets the abbreviated year relative to the century by adjusting dates to be within 80 years before and 20 years after the current date/time.

Take for example that the current date/time is January 1, 1997 and you use a pattern of "MM/dd/yy". The string "01/11/12" would be interpreted as Jan 11, 2012, while the string "05/04/64" would be interpreted as May 4, 1964.

During parsing, only strings that consist of exactly two digits are parsed into the default century. Any other numeric string is interpreted literally. Examples are a one-digit string, three or more digit strings, or a two-digit string that is not all digits ("-1"). So "01/02/3" or "01/02/003" are parsed, by using the same pattern, as Jan 2, 3 AD. Likewise, "01/02/-3" is parsed as Jan 2, 4 BC.

Month

If the number of pattern letters is three or more, the month is interpreted as text. Otherwise, the month is interpreted as a number.

General time zone

Time zones are interpreted as text if they have names. For time zones that represent a GMT offset value, the following syntax is used: GMT +/- Hours:Minutes, which represents GMT plus or minus some offset time in hours and minutes.

Hours must be 0 - 23, and they can be expressed as a single digit or as two digits (for example, 3:00 or 11:00). Minutes must be 00 - 59, and they must be expressed as two digits.

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: +/-HHmm, which represents the current offset from GMT in hours and minutes.

Hours must be 00 - 23, always expressed as two digits, and minutes must be 00 - 59.

For parsing, general time zones are also accepted.

Note: HCL OneTest API also supports localized date and time pattern strings. In these strings, the pattern letters that are described can be replaced with other, locale-dependent, pattern letters. HCL OneTest API does not deal with the localizing of text other than the pattern letters.

Examples

The following examples show how date and time patterns are interpreted in the U.S. locale. The date and time are 2001-07-04 12:08:56 local time in the U.S. Pacific Time time zone.

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