简体   繁体   中英

Javascript - moment.js date object to unix string

I have some moment js date object. The date in object is:

Thu Dec 03 2015 00:00:00 GMT+0100

Im trying to do conversion to unix. So im simply call date_start.unix();

But it returns for me: 1449097200, what means: Wed, 02 Dec 2015 23:00:00 GMT

So what i need to do to have exacly same date like in object? I see its 1 hour diffence... But i cant understand why it work like this.

Thu Dec 03 2015 00:00:00 GMT+0100 is the exact same moment in time as Wed, 02 Dec 2015 23:00:00 GMT is the exact same moment in time as unixtime 1449097200 .

There is no error: when it's 11 o'clock at night in London ( GMT ), it's already midnight in Brussels ( GMT+1 ); both of these happen in the same moment.

I tired a lot of solutions here. - Change localisation in moment object (it was changed the date from moment was for ex in Asian time) then i tried use moment.unix() and again get same date and time!

What fixed my foroblem? - Just simply add +3600 to my time... - Make new utc date.

//First solution
var time = moment_start.unix() + 3600;

//Second solution
var time = new Date.UTC(y,m,d,h,m,s)/100; <--- This give me exacly same unix which i need!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM