TimeMillis ParseDateText() - Custom Format Method

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

Function Signature

 bool ParseDateText( value, string format )

bool 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

bool

Returns true if date parsing was successful.

Technical Details

SBM ModScript version: 11.4.

Example

var t = TimeMillis();
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:

1517617326205
02/02/2018 17:22:06:205 MST

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". TimeMillis is measured in milliseconds and can therefore parse and format millisecond values meaningfully.

Related Topics

TimeMillis