4

How to convert string to timestamp ? For example, I have string:

2012-06-10T10:00:00+04:00
Bdfy
  • 23,141
  • 55
  • 131
  • 179

4 Answers4

8

Use Parse method of Date object as described here.

Community
  • 1
  • 1
Behnam Esmaili
  • 5,835
  • 6
  • 32
  • 63
2

Try moment package for all date parsing it's awesome package.

Ankit
  • 1,916
  • 2
  • 20
  • 33
1

If you are asking this for converting your date to database-specific formats, you can use a very nice library moment.js for various conversions

Mustafa
  • 10,013
  • 10
  • 70
  • 116
0

I tried following in AWS node js lambda function (so mostly like js) and worked fine.

  var arrivalTime='2012-06-10T10:00:00+04:00';
  var d = new Date(arrivalTime);
  console.log('This is -> d ' + d.toString());

For node js lambda the only issue is it always returns UTC so conversion is needed but for js (i.e. on client side) it would return in local time I'd think.

sbp
  • 913
  • 8
  • 19