DateTime.format()

Signature

String format (DateTime d1, String format)

Domain

action, condition

Description

Return the DateTime passed as a formatted String.

Parameters

NameTypeDescription
d1DateTimeA DateTime to be formatted.
formatStringA String containing a format describing how the date should be formatted. e.g. "yyyy-MM-dd HH:mm:ss", "EEE, yyyy-MM-dd HH:mm:ss.SSS Z". SSS (3 S) is required for formating millisecond. i.e. "yyyy-MM-dd HH:mm:ss.SSS" is correct, but "yyyy-MM-dd HH:mm:ss.S" is not valid.

Returns

TypeDescription
StringA String representation of the supplied DateTime in the supplied format.

Cautions

none

Example


String result = DateTime.format (Date.now (), "yyyy-MM-dd HH:mm:ss");

Result is: result contains: 2004-03-11 14:59:04.


String result = DateTime.format (Date.now (), "EEE, yyyy-MM-dd hh:mm:ss.SSS aa Z");

Result is: Wed, 2004-03-11 02:59:04.000 PM -0800.


Notes: The format pattern is compatible with the one in java.text.SimpleDateFormat. 3 S (i.e. SSS) has to be used for formating millisecond correctly.