澳大利亚日期 [英] Australian Date
问题描述
我正在尝试使用澳大利亚日期格式和javascript以及
这让我非常头疼。我的日期是dd / mm / yy。格式。
每当我尝试从我的javascript中检索该日期时,它都会返回
一些没有意义的随机日期。
<例如,
var time = new Object;
time.Date =" 24/11/05" ;; //十一月24,2005
提醒(时间。日期);
现在我的警报框中会收到12/11/2006的内容。
任何想法?
gi **** @ gmail.com 写道:
我正在尝试使用澳大利亚日期格式和javascript和
这让我很头疼。我的日期是dd / mm / yy。格式。
每当我尝试从我的javascript中检索该日期时,它都会返回一些没有意义的随机日期。
例如,
var time = new Object;
我不确定JS解释器会做什么,它不会导致
错误,但我怀疑它不是''做你想的。
如果你真的打算把Object构造函数作为函数调用,那么
使用''()'':
var time = new Object();
time.Date =" 24/11/05" ;; //十一月24,2005
假设时间是一个新实例化的对象,它现在有一个字符串24/11/05的Date
属性。它相当于:
var time = {Date:" 24/11/05" };
time.Date不是日期对象,它是一个字符串。
alert(time.Date);
>现在我会在警报框中收到12/11/2006的内容。
我得到'24 / 11/05''。
但是如果''time''是一个日期对象,并设置为一个特定值,
一次性声明并初始化它:
var time = new Date(2005,11,24);
注意月份数是零索引的; 11是12月。如果你用11美元来表示
,那么请改用10。
日期对象在ECMAScript规范的第15.9节中描述。
< URL:http://www.mozilla.org/js/language/E262-3.pdf>
-
Rob
于2005年11月23日在comp.lang.javascript中写道 :
我正在尝试使用澳大利亚日期格式和javascript,这让我非常头疼。我的日期是dd / mm / yy。格式。
每当我尝试从我的javascript中检索该日期时,它都会返回一些没有意义的随机日期。
例如,
错误的例子,这不像你描述的那样工作:
var time = new Object;
time.Date =" 24/11/05" ;; //十一月24,2005
提醒(时间。日期);
现在我的警报框中会收到12/11/2006的内容。
>
< script type =''text / jscript''>
var time = new Date(" 24/11/05"); //十一月24,2005
document.write(time);
// Tue Dec 11 00:00:00 UTC + 0100 1906
// +0100是我设置的区域时区
< / script>
此代码正常工作,因为机器解释
24/11/05作为1905年第24个月的第11天
[取决于您所在地区的设置是dd / mm / yyyy]
===========================
解决方案[区域设置独立]:
总是使用yyyy / mm / dd
var time = new Date(< 2005/11/24" ); //十一月24,2005
-
Evertjan。
荷兰。
(用我的点替换所有十字架电子邮件地址)
Evertjan。在2005年11月23日上午4:53发表以下内容:于2005年11月23日在comp.lang.javascript中写道 :
< blockquote class =post_quotes>
我正在尝试使用澳大利亚的日期格式和javascript,这让我非常头疼。我的日期是dd / mm / yy。格式。
每当我尝试从我的javascript中检索该日期时,它都会返回一些没有意义的随机日期。
例如,
错误的例子,这不像你描述的那样工作:
var time = new Object;
time.Date =24/11/05; //十一月24,2005
alert(time.Date);
现在,我的警报框中会收到12/11/2006的内容。
< script type =''text / jscript''>
var time = new Date(" 24/11/05"); //十一月24,2005
document.write(time);
// Tue Dec 11 00:00:00 UTC + 0100 1906
// +0100是我设定的区域时区
< / script>
这段代码正常工作,因为机器将其解释为24/115,即1905年第24个月的第11天< br [>
[根据您的区域设置为dd / mm / yyyy]
====================== =====
解决方案[区域设置独立]:
总是使用yyyy / mm / dd
var time = new Date(" ; 2005/11/24英寸); //十一月24,2005
这是一个解决方案,但不是OP的问题。问题是他没有使用日期对象
,他正在向对象添加属性然后
检索该String属性。
-
兰迪
comp.lang.javascript常见问题 - http://jibbering.com/faq &新闻组每周
Javascript最佳实践 - http://www.JavascriptToolbox .com / bestpractices /
Hi,
I''m trying to work with the Australian date formats and javascript and
it''s causing me quite a headache. I have a date in a "dd/mm/yy" format.
Whenever I try to retrieve that date from my javascript, it''d return
some random date that doesn''t make sense.
For example,
var time = new Object;
time.Date = "24/11/05"; //Nov. 24, 2005
alert(time.Date);
Now I''d get something 12/11/2006 in my alert box.
Any ideas?
gi****@gmail.com wrote:Hi,
I''m trying to work with the Australian date formats and javascript and
it''s causing me quite a headache. I have a date in a "dd/mm/yy" format.
Whenever I try to retrieve that date from my javascript, it''d return
some random date that doesn''t make sense.
For example,
var time = new Object;
I''m not sure what the JS interpreter will make of that, it doesn''t cause
an error but I suspect it isn''t doing what you think.
If you really meant to call the Object constructor as a function, then
use ''()'':
var time = new Object();
time.Date = "24/11/05"; //Nov. 24, 2005
Supposing time is a newly instantiated object, it now has a Date
property of the string "24/11/05". It is equivalent to:
var time = { Date : "24/11/05" };
time.Date is not a date object, it is a string.
alert(time.Date);
Now I''d get something 12/11/2006 in my alert box.
I got ''24/11/05''.
But if ''time'' is to be a date object, and set to a particular value,
declare and initialise it in one go:
var time = new Date(2005, 11, 24);
noting that month numbers are zero-indexed; ''11'' is December. If you
meant November, then use ''10'' instead.
Date objects are described in in section 15.9 of the ECMAScript spec.
<URL:http://www.mozilla.org/js/language/E262-3.pdf>
--
Rob
wrote on 23 nov 2005 in comp.lang.javascript:
Hi,
I''m trying to work with the Australian date formats and javascript and
it''s causing me quite a headache. I have a date in a "dd/mm/yy" format.
Whenever I try to retrieve that date from my javascript, it''d return
some random date that doesn''t make sense.
For example,
Wrong example, this is not working like you describe:
var time = new Object;
time.Date = "24/11/05"; //Nov. 24, 2005
alert(time.Date);
Now I''d get something 12/11/2006 in my alert box.
<script type=''text/jscript''>
var time = new Date("24/11/05"); //Nov. 24, 2005
document.write(time);
// Tue Dec 11 00:00:00 UTC+0100 1906
// +0100 being my set regional time zone
</script>
This code works correctly, as the machine interprets
24/11/05 as the 11th day of the 24th month of 1905
[Depending on your regional setting being dd/mm/yyyy]
===========================
Solution [regional settings independent]:
always use yyyy/mm/dd
var time = new Date("2005/11/24"); //Nov. 24, 2005
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)
Evertjan. said the following on 11/23/2005 4:53 AM:wrote on 23 nov 2005 in comp.lang.javascript:Hi,
I''m trying to work with the Australian date formats and javascript and
it''s causing me quite a headache. I have a date in a "dd/mm/yy" format.
Whenever I try to retrieve that date from my javascript, it''d return
some random date that doesn''t make sense.
For example,
Wrong example, this is not working like you describe:var time = new Object;
time.Date = "24/11/05"; //Nov. 24, 2005
alert(time.Date);
Now I''d get something 12/11/2006 in my alert box.
<script type=''text/jscript''>
var time = new Date("24/11/05"); //Nov. 24, 2005
document.write(time);
// Tue Dec 11 00:00:00 UTC+0100 1906
// +0100 being my set regional time zone
</script>
This code works correctly, as the machine interprets
24/11/05 as the 11th day of the 24th month of 1905
[Depending on your regional setting being dd/mm/yyyy]
===========================
Solution [regional settings independent]:
always use yyyy/mm/dd
var time = new Date("2005/11/24"); //Nov. 24, 2005
Thats a solution, but wasn''t the OP''s problem. The problem was he wasn''t
using a Date Object, he was adding a property to an Object and then
retrieving that String property.
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
这篇关于澳大利亚日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!