admin管理员组文章数量:1404759
I want to convert date into timestamp
I have two different format of date Wed May 31 2017 15:33:47 GMT+0530 (India Standard Time)
and 2017-05-31T10:03:47.592Z
. I want
to convert it into timestamp like 1379426880000
.
This is my code.
var noOfDays = 5;
var targetDate = new Date();
targetDate.setDate(targetDate.getDate() - noOfDays);
console.log("targetDate date is " + targetDate); //Wed May 31 2017 15:33:47 GMT+0530 (India Standard Time)
console.log(JSON.stringify(targetDate)); // "2017-05-31T10:03:47.592Z"
I want to convert date into timestamp
I have two different format of date Wed May 31 2017 15:33:47 GMT+0530 (India Standard Time)
and 2017-05-31T10:03:47.592Z
. I want
to convert it into timestamp like 1379426880000
.
This is my code.
var noOfDays = 5;
var targetDate = new Date();
targetDate.setDate(targetDate.getDate() - noOfDays);
console.log("targetDate date is " + targetDate); //Wed May 31 2017 15:33:47 GMT+0530 (India Standard Time)
console.log(JSON.stringify(targetDate)); // "2017-05-31T10:03:47.592Z"
Share
Improve this question
asked Jun 5, 2017 at 10:47
user7791120user7791120
5
- you can use moment.js momentjs. – F.bernal Commented Jun 5, 2017 at 10:51
-
targetDate.valueOf()
gives you the timestamp in milliseconds – Evan Sebastian Commented Jun 5, 2017 at 10:52 - Possible duplicate of convert date to timestamp in javascript? – ponury-kostek Commented Jun 5, 2017 at 12:17
-
@EvanSebastian :
targetDate.valueOf()
is converting my date into timestamp but it's1494135757264
of 13 Digit, while the timestamp which stores in my DB is1496679262
of 10 digit. whats's that last 3 digit stand for – user7791120 Commented Jun 6, 2017 at 5:48 - It's seconds vs milliseconds – Evan Sebastian Commented Jun 6, 2017 at 7:29
1 Answer
Reset to default 4Use this code to get the timestamp.
targetDate.getTime()
本文标签: javascriptHow to convert Date into TimestampStack Overflow
版权声明:本文标题:javascript - How to convert Date into Timestamp - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744851591a2628525.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论