简体   繁体   中英

How to get utc date from timestamp using javascript?

I have a variable containing timestamp ( in seconds generated with php ), I used following code to create date object using javascript

var newdate = new Date(arrivalDate);

then used following code to get formated date in utc

var tempdate = newdate.getUTCFullYear()+'-'+('0' + (newdate.getUTCMonth()+1)).slice(-2)+'-'+('0' + newdate.getUTCDate()).slice(-2);

It returns me a 1 day before date, not sure how to get utc date from a timestamp.

var newdate = new Date(arrivalDate); newdate.toUTCString();

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