2

I want to convert a date given in EST timezone to unix time stamp. I am not sure if the following lines of code gives me the unix time stamp of the EST date 2018-12-30. Can anyone please help.

var estDate = '2018-12-30"; var d = new Date(estDate); var dUnixtime = d.getTime() ;

Amrita
  • 21
  • 3

1 Answers1

1

Try this

Date.prototype.getUnixTime = function() { return this.getTime()/1000|0};
 if(!Date.now) Date.now = function() { return new Date(); }
 Date.time = function() { return Date.now().getUnixTime(); }

 var estDate = '2018-12-30';
 var dUnixtime = new Date(estDate).getUnixTime();
  • The above code will give me the unix time stamp in seconds instead of milliseconds. But I am confused that If I have a EST date do I directly call a getTime() on that to get the Unix time stamp or do I need to convert the EST date to UTC date first before calling the getTime() function? And what do I do if have the EST date as "2018-12-30 10:35:20" – Amrita Jan 10 '19 at 12:50
  • @Amrita I have update my answer . This will convert any date to Unix Timestamp. –  Jan 10 '19 at 13:01
  • @Amrita: If my anwer work for you then please accept my answer –  Jan 10 '19 at 13:03