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

前端 未结 2 1004
迷失自我
迷失自我 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.

    0 讨论(0)
  • 2021-01-12 10:37

    Follow up to Adam R's answer:

    Seems to have been exposed by now:

    localeData.longDateFormat(dateFormat);

    returns the full format of abbreviated date-time formats LT, L, LL and so on

    (source: http://momentjs.com/docs/)

    Get the currently used locale data by moment.localeData()

    0 讨论(0)
提交回复
热议问题