Reputation: 33994
I got stuck converting below time stamp to milliseconds in JavaScript.
I have time stamp in Postgres DB as
2019-02-04 15:38:22.529
I get above time stamp in below format in UI when I read from DB
Mon Feb 04 2019 10:38:22 GMT+0400 (Gulf Standard Time)
How can I convert above UI format time stamp to milliseconds in JavaScript?
Upvotes: 0
Views: 144
Reputation: 3721
the Use of Date
getTime function will return time milliseconds since 2019-02-04 15:38:22.529
:
const date = new Date("2019-02-04 15:38:22.529");
const time = date.getTime();
console.log(time);
Upvotes: 2
Reputation: 1166
Try this, the "Z" means UTC+0:
const time = new Date("2019-02-04T15:38:22.529Z").getTime()
Upvotes: 1
Reputation: 37755
You can use getMilliseconds()
if you want milliseconds according to local time
const date = new Date("2019-02-04 15:38:22.529");
const time = date.getMilliseconds()
console.log(time);
Upvotes: 1