在Javascript中将时间转换为24小时格式

问题描述:

如何将JavaScript的新Date()中的本地时间格式隔离并转换为24小时格式?

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

示例: 2016-09-22T23:21:56.027Z 刚刚成为当地时间的 22:56

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

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

这个 24小时:

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
}