TimeT ParseDateText() - Custom Format Method

Parses a human-readable date string into a TimeT using a custom format.

Function Signature

 void ParseDateText( value, string format )

void ParseDateText( value, string format, TimeZone tz, Locale loc )

Parameters

Parameter Type Description

value

string

The text to parse.

format

string

A string with symbols and literals. See notes below.

tz

TimeZone

Timezone used to determine the point in time represented by the text. If not provided, the current user's timezone is used.

loc

Locale

Locale used during parsing. Especially important if dateformat is set to DateFormatConstants.FROM_LOCALE. Helps identify keywords such as "AM", "PM", month names, etc.

Return

Type Description

None

Technical Details

SBM ModScript version: 11.4.

Example

var t = TimeT();
t.ParseDateText( "2/2/2018 5:22:06:205 PM", "M/d/y h:m:s:Sa" );
Ext.WriteStream( t.date );
Ext.WriteStream( t.FormatDateText( "MM/dd/yyyy HH:mm:ss:SSS z" ) );

Result:

1517620926
02/02/2018 17:22:06:000 PST

Notes

Format value is a string with symbols and literals (literals can be escaped inside single tick ( ' ) values if necessary). Symbols are described in ICU documentation. When formatting, the number of times a symbol occurs determines the length of values during output. For instance, "M" will output January as "1", but "MM" will output January as "01". When parsing, it is often best to provide the simplest option "M", which will work with both "1" and "01". Keep in mind that TimeT is measured in seconds, therefore millisecond values will always be zero.

Related Topics

TimeT