当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - Adjusted time returned by Date function

问题描述:

Im converting a date and time string to a Date object:

var timestamp = "2013-05-02T07:18:37";

var toDate = new Date(timestamp);

console.log('timestamp is: ' + timestamp);

console.log('toDate is ' + toDate);

I get the result:

timestamp is: 2013-05-02T07:18:37

toDate is: Thu May 02 2013 08:18:37 GMT+0100 (GMT Daylight Time)

As you can see, the time is adjusted by 1 hour. Im testing in Chrome on windows 7. I do not want to time adjusted by 1 huor. How do I do this?

网友答案:

Call toUTCString explicitly:

console.log('toDate is ' + toDate.toUTCString());

The specification says about toString (which is implicitly called when you just use toDate) (emphasis mine):

The contents of the String are implementation-dependent, but are intended to represent the Date in the current time zone in a convenient, human-readable form.

分享给朋友:
您可能感兴趣的文章:
随机阅读: