[英]Stringifying date causes timezone change
I am stringifying an object which contains moment
object.我正在字符串化一个包含
moment
对象的对象。 It changes the timezone.它改变了时区。 How do I preserve the time zone even after stringifying the object.
即使在对对象进行字符串化之后,我如何保留时区。
localStorage.setItem("energy_meter", JSON.stringify(localStorageObj));
localStorageObj.ltg.push({
ltgId: message["topic"].split('/')[1],
time: (moment()),
message: message.payloadString,
floorNo: message["topic"].split('/')[2] || null
})
That is the object I am stringifying.那就是我正在串接的对象。
date = new Date();
let hours = date.getHours() - date.getTimezoneOffset() / 60;
let minutes = (date.getHours() - date.getTimezoneOffset()) % 60;
date.setHours(hours);
date.setMinutes(minutes);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.