ArK
ArK

Reputation: 21058

javascript conversion string to UTC date

I'm converting string to timestamp by using

 var  timestamp = new Date(month+"/"+day+"/"+year).getTime()/ 1000;

My question is how to set it as UTC timezone before converting to timestamp ?

Upvotes: 0

Views: 3533

Answers (1)

Amber
Amber

Reputation: 526483

Use the Date.UTC() method instead of .getTime().

var timestamp = Date.UTC(year,month,day) / 1000;

(Note: the month is expected to be from 0-11, not 1-12.)

Upvotes: 2

Related Questions