Convert time to 24 hours format in Javascript [clo

2019-03-17 14:07发布

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.

2条回答
时光不老,我们不散
2楼-- · 2019-03-17 14:37
theDate.format("H:MM")

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

查看更多
我想做一个坏孩纸
3楼-- · 2019-03-17 14:41
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
}
查看更多
登录 后发表回答