Convert time to 24 hours format in Javascript [closed]

删除回忆录丶 提交于 2020-01-11 19:57:47

问题


How can I isolate and convert the local time format in JavaScript's new Date() to a 24 hour format?

Example: 2016-09-22T23:21:56.027Z just becomes 22:56 in local time.


回答1:


new Date("2000-01-01 10:30 AM").getHours() // 10

This is 24 hours:

new Date("2000-01-01 10:30 PM").getHours() // 22

If you want a more general thing:

function get_hours(time_string) {
    return new Date("2000-01-01 " + time_string).getHours() // 22
}



回答2:


theDate.format("H:MM")

Take a look here for more details: http://blog.stevenlevithan.com/archives/date-time-format



来源:https://stackoverflow.com/questions/1788705/convert-time-to-24-hours-format-in-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!