Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.

formatDateTime()

Returns a formatted date time.

Signature

formatDateTime (string | number | Date date, string formatString, string locale)

Parameters

date
Type: string | number | Date
A datetime string in ISO8601 format , or a timestamp in milliseconds, or a Date object. If you provide a String value, use ISO 8601 format to avoid parsing warnings. If no timezone is specified, defaults to the browser timezone offset.
formatString
Type: string
Optional. A string containing tokens to format the given date. For example, "yyyy-MM-dd" formats 15th January, 2017 as "2017-01-15". The default format string comes from the $Locale value provider. For details on available tokens, see Formatting Dates in JavaScript.
locale
Type: string
Optional. A locale to format the given date. The default value is $Locale.langLocale. We strongly recommended that you use the locale value from $Locale. We fall back to the value in $Locale.langLocale if you use an unavailable locale.

Returns

Type: string
A formatted and localized date time string.

Sample Code

1var date = new Date();
2// Returns datetime in the format "Oct 9, 2015 9:00:00 AM"
3$A.localizationService.formatDateTime(date);