Javascript's Date object has a bunch of methods to format dates as strings, including toLocaleDateString(). This method has options for controlling the format, which include language but also more granular options such as "use 2-digit years" or "show long weekday names".

Here are some examples (tests were done in Chrome 64):

const now = new Date;

now.toLocaleString();
// "2/22/2018, 3:25:43 PM"

now.toLocaleString("en-US-u-ca-indian"); // Indian calendar
// "12/3/1939 Saka, 3:25:43 PM"
now.toLocaleString("en-US-u-nu-thai"); // Thai numbering system
// "๒/๒๒/๒๐๑๘, ๓:๒๕:๔๓ PM"
now.toLocaleString("es-ES"); // In Spanish, we put the day first
// "22/2/2018 15:25:43"

now.toLocaleString("en-US", {timeZone: "Europe/London"});
// "2/22/2018, 8:25:43 PM"
now.toLocaleString("en-US", {hour12: false});
// "2/22/2018, 15:25:43"

now.toLocaleString("en-US", {weekday: "short"});
// "Thu"
now.toLocaleString("en-US", {weekday: "long", day: "numeric", month: "short"});
// "Thursday, Feb 22"
now.toLocaleString("es-ES", {weekday: "long", day: "numeric", month: "short"});
// "jueves, 22 feb."

Of course, not all browsers support all options, so it might be best to just use something like Moment.js and spare the trouble.

Previous on JavaScript
Mastodon Mastodon