我正在尝试使用上述格式的 UTCString。我可以转换,问题是转换后它显示在前一天。
var newDate = this.getCellDate(target);
console.log(newDate); --> Dec 05 2014 00:00:00 GMT+0800 (Malay Peninsula Standard Time)
cstDate = newDate.toISOString();
console.log(cstDate); -- > 2014-12-04 --- > **Expected --> 2014-12-05**
最佳答案
使用 Date.UTC() 方法
var now = new Date(), // my date Thu Dec 04 2014 13:02:15 GMT+0300 (RTZ 2 (зима))
year = now.getFullYear(),
month = now.getMonth(),
day = now.getDay(),
hours = now.getHours(),
minutes = now.getMinutes(),
utcDate;
utcDate = new Date(Date.UTC(year, month, day, hours, minutes)); // Thu Dec 04 2014 16:02:00 GMT+0300 (RTZ 2 (зима))
Ext.Msg.alert('UTC Date', Ext.Date.format(utcDate, 'Y-m-d'));
看看这个“Thu Dec 04 2014 16:02:00” - 我得到了 utc 时间(+3 小时)
<小时/>关于javascript - 将 UTC 字符串转换为 yyyy-mm-dd,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27290125/