Using moment.js, how to display the current date format for the user?

前端 未结 2 1005
迷失自我
迷失自我 2021-01-12 09:58

Given a text field, I want to have a suitable placeholder. A typical placeholder will be something like: \"mm/dd/yyyy\".

However, I would like to use locale-aware d

2条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-12 10:19

    I don't think it's exposed nicely, but if the browser has its language configured correctly you can do something like this:

    var lang = navigator.languages ? navigator.languages : navigator.language;
    
    moment().locale(lang).localeData()._longDateFormat['L']
    

    Languages behave slightly differently depending on which browser you're using, so don't know how reliable this is.

提交回复
热议问题