Dra*_*SAN 0 javascript timestamp date node.js
我正在使用javascript/node.js中的覆盆子pi(raspbian)上的预定电视
我提取了.smil文件中播放内容的信息,其中一个字段是预定的,格式为"YYYY-MM-DD hh:mm:ss"的字符串
为了比较它们和系统时间,我想在UNIX时间戳中进行转换.
有没有比这样的函数更好的方法:
function (stime){
var time=0, cache=0, scache;
scache=stime.substr(0, 4);
cache=parseInt(scache);
time=cache*365*24*60*60;
...
return time;
}
Run Code Online (Sandbox Code Playgroud)
对于mounth来说,一天......?
可能这可以帮助
var date = new Date('2009-07-15 00:00:00'.split(' ').join('T'))
Run Code Online (Sandbox Code Playgroud)
这将为您提供日期对象并从中获取时间戳
date.getTime() / 1000
Run Code Online (Sandbox Code Playgroud)
除以1000,因为getTime将以毫秒为单位给出时间戳