format Property (Intl.DateTimeFormat)

format Property (Intl.DateTimeFormat)

 

Returns a function that formats a locale-specific date by using the specified date/time formatter settings.

dateTimeFormatObj.format

dateTimeFormatObj

Required. The name of the DateTimeFormat object to use as a formatter.

The function returned by the format property takes a single argument, date, and returns a string that represents the localized date by using the options specified in the DateTimeFormat object. The date parameter of the returned function must be a number, date string, or a Date object. If date is not provided, the function uses Date.now as the default input value.

The following example uses a DateTimeFormat object to localize the date "Dec 1, 2007" into German and reformat it.

var dtFormat = new Intl.DateTimeFormat(["de"], {
    year: "numeric",
    month: "long",
    day: "2-digit",
    hour: "numeric"
});

if (console && console.log) {
    console.log(dtFormat.format(new Date("Dec 1, 2007")));
    // Returns 01. Dezember 2007 00:00
}

Requirements

Supported in the Internet Explorer 11 standards document mode. Also supported in Store apps (Windows 8.1 and Windows Phone 8.1). See Version Information.

Not supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards, Internet Explorer 10 standards. Not supported in Windows 8.

Show:
© 2016 Microsoft