日期字符串转换为JavaScript / jQuery中的unix时间戳 [英] Date string conversion to unix timestamp in JavaScript / jQuery
本文介绍了日期字符串转换为JavaScript / jQuery中的unix时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这种格式的日期字符串:
I have date string in this format:
2009-07-15 00:00:00 - 2009-07-15 08:16:23
任何人都可以帮我调整日期字符串到unix时间戳到类似的东西这个:
Could anyone help me to tweak the date string to unix timestamp into something like this:
1247634000 - 1247663783
我使用 GMT-5
时区。
可以使用哪些JavaScript或jQuery技术?
What JavaScript or jQuery techniques could be used?
推荐答案
var input = "2009-07-15 00:00:00 - 2009-07-15 08:16:23";
input = input.split(" - ").map(function (date){
return Date.parse(date+"-0500")/1000;
}).join(" - ");
Date.parse
docs
注意:这不适用于旧浏览器,因为我正在使用 Array.map
,但我想你应该很容易就可以了。
Note: This won't work on old browsers since I'm using Array.map
, but I think you should easily be able to shim it.
这篇关于日期字符串转换为JavaScript / jQuery中的unix时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文