我有一个长int值:20140307080000。这实际上是2014-03-07 08:00:00的日期时间。我已经在JS中尝试了Date.parse并将其转换为字符串,但是,我无法将其作为Javascript日期对象检索。是否有任何javascript或D3内置方法将其转换为日期对象而不是手动拆分它?
答案 0 :(得分:1)
// Your date String
var d = "20140307080000";
// Convert it to the format 2014-03-07 08:00:00
var f = d.replace(/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/, "$1-$2-$3 $4:$5:$6");
// Alerting after parse
alert(new Date(Date.parse(f)));
// This will alert "Fri Mar 07 2014 08:00:00 GMT+0530 (IST)"