< 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。 荷兰。 (用我的点替换所有十字架电子邮件地址) 错误的例子,这不像你描述的那样工作: < 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天 [根据您的区域设置为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 andit''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 returnsome random date that doesn''t make sense.For example,var time = new Object;time.Date = "24/11/05"; //Nov. 24, 2005alert(time.Date);Now I''d get something 12/11/2006 in my alert box.Any ideas? 解决方案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 youmeant 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<script type=''text/jscript''>var time = new Date("24/11/05"); //Nov. 24, 2005document.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 interprets24/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/ddvar time = new Date("2005/11/24"); //Nov. 24, 2005--Evertjan.The Netherlands.(Replace all crosses with dots in my emailaddress) Wrong example, this is not working like you describe: <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, 2005Thats a solution, but wasn''t the OP''s problem. The problem was he wasn''tusing a Date Object, he was adding a property to an Object and thenretrieving that String property.--Randycomp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weeklyJavascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/ 这篇关于澳大利亚日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-11 16:40