getUTCFullYear返回1月1日的错误信息???? [英] getUTCFullYear returns wrong info for 1st Jan????
问题描述
< code>
var dt = new Date(2004,0,1);
alert(dt.getDate()); //返回正确的日期
alert(dt.getUTCFullYear()); //返回2003
< / code>
为什么会这样?还是我错过了什么?
问候,
Rithish。
>或者我错过了什么?
你错过了时区差异。当人们已经在你的位置喝新年香槟时,格林威治的人们只需将它们放在凉爽的地方:-)
(格林威治标准时间= GMT = UTC)
于2005年6月7日在comp.lang.javascript中写道 :
< code>
var dt = new Date(2004,0,1);
alert(dt.getDate()); //返回正确的日期
alert(dt.getUTCFullYear()); //返回2003
< / code>
是我遗失了什么?
是
为什么会这样?
< script type =" text / JavaScript">
var dt = new Date(2004,0,1); //输入本地日期
alert(dt.getDate()); //返回正确的LOCAL日期
alert(dt.getFullYear()); //返回LOCAL年
alert(dt.getUTCDate()); //返回正确的UTC日期
alert(dt.getUTCFullYear()); //返回UTC年
< / script>
-
Evertjan。
荷兰。
(用我的电子邮件地址替换所有带点的十字架)
JRS:在文章< 11*********************@g14g2000cwa.googlegroups。 com>,
日期:2005年6月7日星期二03:54:01,见于新闻:comp.lang.javascript,
ri ***** @ gmail.com 发布:< code>
var dt = new Date(2004,0,1) ;
alert(dt.getDate()); //返回正确的日期
alert(dt.getUTCFullYear()); //返回2003
< / code>
为什么会这样?或者我错过了什么?
在询问日期问题时,请务必提供真实的行踪;经常
很重要。谷歌不明智地提出美国PDT日期戳。
我推断你的系统是为旧世界本地化的(但不是
英国,爱尔兰,葡萄牙,冰岛,NW Africa),因为你的民用时钟(1月份的b $ b $)在GMT / UTC之前运行。
对于当地的格里高利年,请使用getFullYear( )。
-
?约翰斯托克顿,英国萨里。 ?@merlyn.demon.co.uk Turnpike v4.00 IE 4?
< URL:http://www.jibbering.com/faq/> JL / RC:新闻常见问题:comp.lang.javascript
< URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr数学,日期,来源。
< URL:http://www.merlyn.demon.co.uk/> TP / BP / Delphi / jscr /& c,常见问题项目,链接。
<code>
var dt = new Date(2004, 0, 1);
alert ( dt.getDate() ); // returns proper date
alert ( dt.getUTCFullYear() ); // returns 2003
</code>
Why is this so? Or is that I am missing something?
Regards,
Rithish.
> Or is that I am missing something?
You are missing the time zone difference. When people are already
drinking New Year champaign in your location, people in Greenwich just
putting it in the cooler :-)
(Greenwich Mean Time = GMT = UTC)
wrote on 07 jun 2005 in comp.lang.javascript:
<code>
var dt = new Date(2004, 0, 1);
alert ( dt.getDate() ); // returns proper date
alert ( dt.getUTCFullYear() ); // returns 2003
</code>
is that I am missing something?
yes
Why is this so?
<script type="text/JavaScript">
var dt = new Date(2004, 0, 1); // enter local date
alert ( dt.getDate() ); // returns proper LOCAL date
alert ( dt.getFullYear() ); // returns LOCAL year
alert ( dt.getUTCDate() ); // returns proper UTC date
alert ( dt.getUTCFullYear() ); // returns UTC year
</script>
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)
JRS: In article <11*********************@g14g2000cwa.googlegroups. com>,
dated Tue, 7 Jun 2005 03:54:01, seen in news:comp.lang.javascript,
ri*****@gmail.com posted :<code>
var dt = new Date(2004, 0, 1);
alert ( dt.getDate() ); // returns proper date
alert ( dt.getUTCFullYear() ); // returns 2003
</code>
Why is this so? Or is that I am missing something?
When asking date questions, always give your true whereabouts; it often
matters. Google unwisely puts a US PDT datestamp.
I deduce that your system is localised for the Old World (but not the
UK, Ireland, Portugal, Iceland, NW Africa), since your civil clock (in
January) is running ahead of GMT/UTC.
For the local Gregorian year, use getFullYear() .
--
? John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ?
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
这篇关于getUTCFullYear返回1月1日的错误信息????的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!