How to format date and display month and day based on user language

后端 未结 2 1940
悲哀的现实
悲哀的现实 2020-12-22 01:55

I am trying to display the date and time in javascript based on users browser language preference. I am receiveing the date in UTC format and by using toLocaleString() i am

2条回答
  •  执笔经年
    2020-12-22 02:44

    If you want consistent output regardless of browser, moment.js is a good option.

    // set the desired language
    moment.lang('sv');
    
    // use one of the localized format strings
    var s = moment(yourDate).format('LLLL');
    

    There are live examples on the moment.js home page, showing all of the available languages. I don't believe there is currently support for Greek, but since it is open-source you could always add it yourself.

提交回复
热议问题