Amrita
Amrita

Reputation: 21

convert EST date to Unix Time Stamp in Javascript

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() ;

Upvotes: 2

Views: 217

Answers (1)

user10186369
user10186369

Reputation:

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();

Upvotes: 1

Related Questions