DEV Community

loading...

Discussion on: Formatting a date in JavaScript

Collapse
afflexux profile image
afflexux

This is great, thanks.

I've extracted it out to a function in plugins/filters.js, I find it easier to put really useful stuff in there and just drop that full file into new nuxt projects.

Vue.filter('formatDate', function (date) {
const options = {
weekday: 'short',
year: 'numeric',
month: 'long',
day: 'numeric',
hour: '2-digit',
minute: '2-digit',
hour12: false,
}
return new Date(date).toLocaleDateString('en', options)
})

Added options to also format and show the time.

Result >>

Thu, October 22, 2020, 23:09

Forem Open with the Forem app