开发者

Convert time to 24 hours format in Javascript [closed]

开发者 https://www.devze.com 2022-12-12 03:19 出处:网络
Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the prob开发者_如何学Clem by editing this post
Closed. This question needs details or clarity. It is not currently accepting answers.

Want to improve this question? Add details and clarify the prob开发者_如何学Clem by editing this post.

Closed 9 years ago.

Improve this question

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.


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
}


In moment.js you can do:

theDate.format("H:MM")

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

0

精彩评论

暂无评论...
验证码 换一张
取 消