3

I want to convert datetime like '2015-05-01 05:13:43' into timestamp. Is there Any way to do it using JavaScript?

Swapnil Yeole
  • 406
  • 3
  • 12
  • 26

2 Answers2

4

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.

hsz
  • 148,279
  • 62
  • 259
  • 315
1

You can do it!

let dateToConvert = '2015-05-01 05:13:43'
let date = new Date(dateToConvert)
let timestamp = date.getTime()
Carmelo Catalfamo
  • 93
  • 1
  • 4
  • 15