The ECMA-402 (ECMAScript Intl API) standard specifies standard objects and methods that enable language sensitive date and time formatting (available in Chrome 24+, Firefox 29+, IE11+, Safari10+).
You can now either use the Date.prototype.toLocaleDateString
method if you just want to format one date.
const today = new Date();
const options = {
weekday: "long",
year: "numeric",
month: "long",
day: "numeric",
};
const date = today.toLocaleDateString("de-DE", options);
console.log(date);
Or, you can make use of the Intl.DateTimeFormat
object, which allows you to cache an object with most of the computations done so that formatting is fast. This is useful if you have a loop of dates to format.
const options = {
weekday: "long",
year: "numeric",
month: "long",
day: "numeric",
};
const dateFormatter = new Intl.DateTimeFormat("de-DE", options);
const dates = [Date.UTC(2012, 11, 20, 3, 0, 0), Date.UTC(2014, 4, 12, 8, 0, 0)];
dates.forEach((date) => console.log(dateFormatter.format(date)));