我有一个非标准的非标准日期
if(req.params.id){
//solution with id
}
if(req.params.timestamp && req.params.count){
//solution with timestamp and count but without id
}
有没有办法将它转换为javascript中的unix时间戳?
答案 0 :(得分:1)
new Date("Jul-23-2017").getTime();
答案 1 :(得分:0)
要确保将有效值传递给日期构造函数,您可以自己解析日期
var months = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
var date = "Jul-23-2017";
var parts = date.split('-');
var unix = (new Date(parts[2], months.indexOf(parts[0]), parts[1])).getTime();
console.log(unix)