Jed Jed - 14 days ago 7
Javascript Question

JavaScript full names for day-of-week and month

The string that is returned from

(new Date()).toString()
looks something like this:

"Tue Nov 22 2016 14:14:51 GMT-0800 (Pacific Standard Time)"


Is there a built-in method/constructor that we can use that will not abbreviate the day-of-week and/or month? In other words, does JS support this:

"Tuesday November 22 2016 14:14:51 GMT-0800 (Pacific Standard Time)"

Answer

If don't need to support old browsers (older than IE 11) you can use toLocalDateString().

Example:

new Date().toLocaleDateString('en-US', {
    weekday: 'long',
    month: 'long',
    day: 'numeric',
    year: 'numeric',
    hour: '2-digit',
    minute: '2-digit',
    second: '2-digit',
    timeZoneName: 'short'
})

But moment.js way more comfortable.

See MDN Date.prototype.toLocaleDateString() for more information.