Javascript — Detect if user's locale are set to use 12-hour or 24-hour time format

后端 未结 5 2143
花落未央
花落未央 2021-01-04 09:02

One way to do that is to parse new Date().toLocaleString(). But this doesn\'t work in chromium/webkit since the string it returns isn\'t dependent of the user\'

5条回答
  •  日久生厌
    2021-01-04 09:37

    I know it would be the least favoured way of doing it, but could you not just check the time?

    If the time is before 12, set the time to 1pm and test if the output is 13 or 1.

    I know its a shoehorn of an idea, but if placed into a nice Date.prototype.is24hour(), returns true; It could work nicely?

    I use http://www.datejs.com/ with dates. tends to do everything I need! So you could use that alongside a custom prototype function, and that would give you what you need!

提交回复
热议问题