GMT日期格式异常 [英] GMT Date Format Anomaly
问题描述
以下代码运行于2004年12月25日星期六19:54:18 GMT-0600(中央
标准时间)
var today = new Date();
var GMTDate = today.toGMTString();
document.write(" GMTDate:" + GMTDate);
代码返回:
Sun,2004年12月26日19:54:18 GMT(代码实际运行后的第二天)
请告知为何将来这一天,并建议如何获得
正确的GMT日期格式。
<%= Clinton Gallagher
When the following code is run on Sat Dec 25 2004 19:54:18 GMT-0600 (Central
Standard Time)
var today = new Date();
var GMTDate = today.toGMTString();
document.write("GMTDate: " + GMTDate);
The code returns:
Sun, 26 Dec 2004 19:54:18 GMT (the next day after the code was actually run)
Please advise why the day is in the future and suggest how to get the
correct GMT date format.
<%= Clinton Gallagher
推荐答案
clintonG说:
clintonG said:
以下代码运行于2004年12月25日星期六19:54:18 GMT-0600(中部标准时间)
var today = new Date();
var GMTDate = today.toGMTString();
document.write(" ; GMTDate:+ GMTDate;
代码返回:
Sun,2004年12月26日19:54:18 GMT(代码实际运行后的第二天)
请告知未来的日期,并建议如何获得正确的GMT日期格式。
When the following code is run on Sat Dec 25 2004 19:54:18 GMT-0600 (Central
Standard Time)
var today = new Date();
var GMTDate = today.toGMTString();
document.write("GMTDate: " + GMTDate);
The code returns:
Sun, 26 Dec 2004 19:54:18 GMT (the next day after the code was actually run)
Please advise why the day is in the future and suggest how to get the
correct GMT date format.
您确定它显示时间为19:54:18?
当时CST它*是GMT的第二天。
Are you sure it shows the time as 19:54:18?
At that time CST it *is* the next day in GMT.
谢谢你你的注意力。我们现在可以抓一点时间注意
的差异可能是因为我复制并粘贴以使事情更容易阅读
但请阅读或运行以下内容请...
//示例A
//返回:Sun Dec 26 2004 2004 10:49:25 GMT-0600(中央标准时间)
var expDate = new Date();
document.write(" expDate:" + expDate +"< br />");
//示例B
//返回:Sun,2004年12月26日16:49:25 GMT
var today = new Date();
var myDateString = today.toGMTString();
document.write(" myDateString:" + myDateString);
我明白了什么现在。示例A使用日期方法
返回时间作为CST,即GMT-0600小时(比GMT少6小时)所以
坐在一个地区的计算机前使用CST(我)并运行
示例B在格林威治午夜不到6小时的时间将
表示日期为''第二天' '当使用toGMTString()方法覆盖Date()方法
时。
<%= Clinton Gallagher
>
" Lee" < RE ************** @ cox.net>在消息中写道
news:cq ********* @ drn.newsguy.com ...
Thank you for your attention. We can scratch that time for now noting the
discrepancy may be because I copied and pasted to make things easier to read
but read or run the following please...
//Example A
//Returns: Sun Dec 26 2004 10:49:25 GMT-0600 (Central Standard Time)
var expDate = new Date( );
document.write("expDate: " + expDate + "<br />");
//Example B
//Returns: Sun, 26 Dec 2004 16:49:25 GMT
var today = new Date( );
var myDateString = today.toGMTString( );
document.write("myDateString: " + myDateString);
I understand what is going on now. Example A uses the Date method that
returns time as CST which is GMT-0600 hours (6 hours less than GMT) so
sitting in front of a computer in a region that uses CST (me) and running
Example B at a time of day less than 6 hours from midnight in Greenwich will
indicate the date as the ''next day'' when the the Date( ) method is overriden
by the toGMTString( ) method.
<%= Clinton Gallagher
"Lee" <RE**************@cox.net> wrote in message
news:cq*********@drn.newsguy.com...
clintonG说:
clintonG said:
以下代码运行于2004年12月25日星期六19:54:18 GMT-0600
(CentralStandard Time)
var today = new Date();
var GMTDate = today.toGMTString();
document.write(" GMTDate:" + GMTDate);
代码返回:
Sun,2004年12月26日格林尼治标准时间19:54:18(代码实际上是
运行后的第二天)
请告知未来的日期,并建议如何获得正确的GMT日期格式。
When the following code is run on Sat Dec 25 2004 19:54:18 GMT-0600 (CentralStandard Time)
var today = new Date();
var GMTDate = today.toGMTString();
document.write("GMTDate: " + GMTDate);
The code returns:
Sun, 26 Dec 2004 19:54:18 GMT (the next day after the code was actually run)
Please advise why the day is in the future and suggest how to get the
correct GMT date format.
你确定时间显示为19:54:18吗?
当时CST它*是GMT的第二天。
Are you sure it shows the time as 19:54:18?
At that time CST it *is* the next day in GMT.
>
On Sun,2004年12月26日11:03:47 -0600,clintonG
< cs ********* @ REMOVETHISTEXTmetromilwaukee。 COM>写道:
[snip]
On Sun, 26 Dec 2004 11:03:47 -0600, clintonG
<cs*********@REMOVETHISTEXTmetromilwaukee.com> wrote:
[snip]
var today = new Date();
var myDateString = today.toGMTString();
var today = new Date( );
var myDateString = today.toGMTString( );
只是你知道,不推荐使用toGMTString方法,而是支持
toUTCString方法。但是效果如果相同的话。
[snip]
Mike
请不要顶-post。
-
Michael Winter
替换.invalid与.uk通过电子邮件回复。
Just so you know, the toGMTString method is deprecated in favour of the
toUTCString method. The effect if the same, though.
[snip]
Mike
Please don''t top-post.
--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
这篇关于GMT日期格式异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!