Kis*_*shh 26 javascript time datetime hour
如何将JavaScript中的本地时间格式隔离并转换new Date()为24小时格式?
示例:2016-09-22T23:21:56.027Z只是22:56在当地时间.
She*_*tJS 21
new Date("2000-01-01 10:30 AM").getHours() // 10
Run Code Online (Sandbox Code Playgroud)
这是 24小时:
new Date("2000-01-01 10:30 PM").getHours() // 22
Run Code Online (Sandbox Code Playgroud)
如果你想要更通用的东西:
function get_hours(time_string) {
return new Date("2000-01-01 " + time_string).getHours() // 22
}
Run Code Online (Sandbox Code Playgroud)
theDate.format("H:MM")
Run Code Online (Sandbox Code Playgroud)
请查看此处了解更多详情:http://blog.stevenlevithan.com/archives/date-time-format