admin 管理员组文章数量: 1086019
I m working on a scheduled TV on a raspberry pi (raspbian) in javascript/node.js
I extract the information of what to play in a .smil file, and one of the field is scheduled, wich is a string of the format "YYYY-MM-DD hh:mm:ss"
To make parison between them and the system time, I would like to convert it in UNIX timestamp.
Is there a better way than a function like this one:
function (stime){
var time=0, cache=0, scache;
scache=stime.substr(0, 4);
cache=parseInt(scache);
time=cache*365*24*60*60;
...
return time;
}
And so on for mounth, day...?
I m working on a scheduled TV on a raspberry pi (raspbian) in javascript/node.js
I extract the information of what to play in a .smil file, and one of the field is scheduled, wich is a string of the format "YYYY-MM-DD hh:mm:ss"
To make parison between them and the system time, I would like to convert it in UNIX timestamp.
Is there a better way than a function like this one:
function (stime){
var time=0, cache=0, scache;
scache=stime.substr(0, 4);
cache=parseInt(scache);
time=cache*365*24*60*60;
...
return time;
}
And so on for mounth, day...?
Share Improve this question asked Jul 29, 2013 at 10:03 DrakaSANDrakaSAN 7,9088 gold badges57 silver badges96 bronze badges1 Answer
Reset to default 7May be this can help
var date = new Date('2009-07-15 00:00:00'.split(' ').join('T'))
that will give you date object and to get timestamp from it you can do
date.getTime() / 1000
dividing by 1000 because getTime will give timestamps in milliseconds
本文标签: javascriptString date to unix timestampStack Overflow
版权声明:本文标题:javascript - String date to unix timestamp - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744062899a2527051.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论