我在云存储上存储的UTC时间戳为“Sun Feb 22 02:30:00 UTC 2015”。
在我的javascript中,我将UTC时间解析为字符串以创建Date对象。
var obsDTStr = 'Sun Feb 22 10:30:00 CST 2015'; // this is correct as I am in Time Zone +8
console.log(obsDTStr); // console prints out "Sun Feb 22 10:30:00 CST 2015" which is also correct
var obsDT = new Date(obsDTStr); // create a Date object with the string
console.log(obsDT.toString()); // console prints out "Mon Feb 23 2015 00:30:00 GMT+0800 (China Standard Time)" which is incorrect
我不确定为什么结果如此奇怪。
有什么想法吗?谢谢!
答案 0 :(得分:0)
尝试
console.log(obsDT.toUTCString());