我有以下功能,它应该以UTC格式读取时间并以当地时间返回,有时它会增加2小时(正确),有时增加4小时。这是为什么?可能是什么原因?
value = time in UTC
toLocalDate(value) {
let string = new Date(value);
let date = new Date();
date.setUTCFullYear(string.getFullYear(), string.getMonth(), string.getDate());
date.setUTCHours(string.getHours(), string.getMinutes(), string.getSeconds(), 0);
return date;
}
示例数据:
Value: 2017-08-23T06:00:00
Expected output: Wed Aug 23 2017 08:00:00 GMT+0200 (Central European Daylight Time)
Output: Wed Aug 23 2017 10:00:00 GMT+0200 (Central European Daylight Time)
在某些设备(如我的手机或计算机)上,它会返回预期的输出。 在我朋友的设备(移动设备)上,它返回第二个输出。