formatDate

[ Function ]

public static formatDate(
    date: Date,
    options?: TcHmi.Localization.FormatOptions
): string | null;

Formats a Javascript timestamp in a specific time zone, language, and level of detail as a string. The output also contains milliseconds.

If the user does not specify a time zone or locale, the settings of the current user apply. These are also available under TcHmi.Server.getCurrentUserConfig.

Parameter

Name

Type

Description

date

Date

To the formatting date

options [optional]

TcHmi.Localization.FormatOptions

Formatting options

Return value

Type

Description

string, null

Formatted string or null in case of error.

formatDate 1:

Available from version 1.10.1336.10

Sample - JavaScript

var date = new Date('2019-12-02T14:15:16.017Z');
var result = TcHmi.Localization.formatDate(date);
console.log(result); // For a user with timeFormatLocale 'de-DE' and timeZone set to 'Europe/Berlin': 2.12.2019, 15:15:16,017
var date = new Date('2019-12-02T14:15:16.017Z');
var result = TcHmi.Localization.formatDate(date, {
    type: 'time',
    timeZone: 'Europe/Helsinki',
    locale: 'fr-FR'
});
console.log(result); // '16:15:16,017'
formatDate 2:

Available from version 1.10.1336.10