开发者

javascript conversion string to UTC date

开发者 https://www.devze.com 2022-12-29 02:06 出处:网络
I\'m converting string to timestamp by using vartimestamp = new Date(month+\"/\"+day+\"/\"+year).getTime()/ 1000;

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 tim开发者_开发问答estamp ?


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.)

0

精彩评论

暂无评论...
验证码 换一张
取 消