FrontendDeveloper.in

Vue.js question detail

How to implement DateTime localization?

You can localize the datetime with definition formats(e.g. short, long, etc).

Lets follow below steps to localize date and time,

  1. For example, you can add definition formats for English and Jappan locale as below
const dateTimeFormats = {
'en-US': {
short: {
year: 'numeric', month: 'short', day: 'numeric'
},
long: {
year: 'numeric', month: 'short', day: 'numeric',
weekday: 'short', hour: 'numeric', minute: 'numeric'
}
},
'ja-JP': {
short: {
year: 'numeric', month: 'short', day: 'numeric'
},
long: {
year: 'numeric', month: 'short', day: 'numeric',
weekday: 'short', hour: 'numeric', minute: 'numeric', hour12: true
}
}
}
  1. After that You need to specify the dateTimeFormats option of VueI18n constructor
const i18n = new VueI18n({
dateTimeFormats
})

new Vue({
i18n
}).$mount('#app')
  1. And then add them to the template
  1. Finally it outputs the result
Back to all Vue.js questions
Get LinkedIn Premium at Rs 399