Reputation: 528
I want to convert datetime like '2015-05-01 05:13:43' into timestamp. Is there Any way to do it using JavaScript?
Upvotes: 3
Views: 4554
Reputation: 152226
With pure JS you can try with:
new Date(Date.parse('2015-05-01 05:13:43+0000')).getTime() / 1000
It's important to add +0000
at the end of the string - otherwise browser will use your local timezone and add/remove few hours from the result.
getTime
method gives you time in ms - so we have to divide it by 1000
.
Upvotes: 4
Reputation: 93
You can do it!
let dateToConvert = '2015-05-01 05:13:43'
let date = new Date(dateToConvert)
let timestamp = date.getTime()
Upvotes: 1