两天后就端午节了,我想家。。。。我快要回去了。。。。
目前项目情况比较忙,但是晚上是我的天下,哈哈哈!
今天晚上看到了这篇文章:http://blog.csdn.net/KimSoft/archive/2009/05/19/4202583.aspx
因此就做了一下new Date() 测试,看看形参可能为负值,结果让我吃惊!
代码如下:(现在的CSDN代码编辑器打不开,所以就不用了)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> JavaScript new Date() Test </title>
</head>
<body>
<script type="text/javascript">
<!--
document.write("// day-- <br />");
/************* day-- *************/
document.write("arguments: [2009, 4, 1] : " + new Date(2009, 4, 1).toLocaleString() + "<br />");
document.write("arguments: [2009, 4, 0] : " + new Date(2009, 4, 0).toLocaleString() + "<br />");
document.write("arguments: [2009, 4, -1] : " + new Date(2009, 4, -1).toLocaleString() + "<br />");
document.write("arguments: [2009, 4, -2] : " + new Date(2009, 4, -2).toLocaleString() + "<br />");
document.write("// month--<br />");
/************* month-- *************/
document.write("arguments: [2009, 1, 1] : " + new Date(2009, 1, 1).toLocaleString() + "<br />");
document.write("arguments: [2009, 0, 1] : " + new Date(2009, 0, 1).toLocaleString() + "<br />");
document.write("arguments: [2009, -1, 1] : " + new Date(2009, -1, 1).toLocaleString() + "<br />");
document.write("arguments: [2009, -2, 1] : " + new Date(2009, -2, 1).toLocaleString() + "<br />");
document.write("// year-- <br />");
/************* year-- *************/
document.write("arguments: [2009, 1, 1] : " + new Date(2009, 1, 1).toLocaleString() + "<br />");
document.write("arguments: [009, 1, 1] : " + new Date(009, 1, 1).toLocaleString() + "<br />");
document.write("arguments: [09, 1, 1] : " + new Date(09, 1, 1).toLocaleString() + "<br />");
document.write("arguments: [9, 1, 1] : " + new Date(9, 1, 1).toLocaleString() + "<br />");
document.write("arguments: [0, 1, 1] : " + new Date(0, 1, 1).toLocaleString() + "<br />");
document.write("arguments: [-1, 1, 1] : " + new Date(-1, 1, 1).toLocaleString() + "<br />");
document.write("arguments: [-2, 1, 1] : " + new Date(-2, 1, 1).toLocaleString() + "<br />");
document.write("arguments: [-3, 1, 1] : " + new Date(-3, 1, 1).toLocaleString() + "<br />");
document.write("arguments: [-2009, 1, 1] : " + new Date(-2009, 1, 1).toLocaleString() + "<br />");
//-->
</script>
</body>
</html>
测试结果:
运行环境:IE8.0 、IE7.0:
// day--
arguments: [2009, 4, 1] : 2009年5月1日 0:00:00
arguments: [2009, 4, 0] : 2009年4月30日 0:00:00
arguments: [2009, 4, -1] : 2009年4月29日 0:00:00
arguments: [2009, 4, -2] : 2009年4月28日 0:00:00
// month--
arguments: [2009, 1, 1] : 2009年2月1日 0:00:00
arguments: [2009, 0, 1] : 2009年1月1日 0:00:00
arguments: [2009, -1, 1] : 2008年12月1日 0:00:00
arguments: [2009, -2, 1] : 2008年11月1日 0:00:00
// year--
arguments: [2009, 1, 1] : 2009年2月1日 0:00:00
arguments: [009, 1, 1] : 1909年2月1日 0:00:00
arguments: [09, 1, 1] : 1909年2月1日 0:00:00
arguments: [9, 1, 1] : 1909年2月1日 0:00:00
arguments: [0, 1, 1] : 1900年2月1日 0:00:00
arguments: [-1, 1, 1] : Mon Feb 1 00:00:00 UTC+0800 2 B.C.
arguments: [-2, 1, 1] : Sun Feb 1 00:00:00 UTC+0800 3 B.C.
arguments: [-3, 1, 1] : Sat Feb 1 00:00:00 UTC+0800 4 B.C.
arguments: [-2009, 1, 1] : Fri Feb 1 00:00:00 UTC+0800 2010 B.C.
运行环境:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10
// day--
arguments: [2009, 4, 1] : 2009年5月1日 0:00:00
arguments: [2009, 4, 0] : 2009年4月30日 0:00:00
arguments: [2009, 4, -1] : 2009年4月29日 0:00:00
arguments: [2009, 4, -2] : 2009年4月28日 0:00:00
// month--
arguments: [2009, 1, 1] : 2009年2月1日 0:00:00
arguments: [2009, 0, 1] : 2009年1月1日 0:00:00
arguments: [2009, -1, 1] : 2008年12月1日 0:00:00
arguments: [2009, -2, 1] : 2008年11月1日 0:00:00
// year--
arguments: [2009, 1, 1] : 2009年2月1日 0:00:00
arguments: [009, 1, 1] : 1909年2月1日 0:00:00
arguments: [09, 1, 1] : 1909年2月1日 0:00:00
arguments: [9, 1, 1] : 1909年2月1日 0:00:00
arguments: [0, 1, 1] : 1900年2月1日 0:00:00
arguments: [-1, 1, 1] : -1年2月1日 0:00:00
arguments: [-2, 1, 1] : -2年2月1日 0:00:00
arguments: [-3, 1, 1] : -3年2月1日 0:00:00
arguments: [-2009, 1, 1] : -2009年2月1日 0:00:00
运行环境:遨游 2.5.2.3272 UNICODE
// day--
arguments: [2009, 4, 1] : 2009年5月1日 0:00:00
arguments: [2009, 4, 0] : 2009年4月30日 0:00:00
arguments: [2009, 4, -1] : 2009年4月29日 0:00:00
arguments: [2009, 4, -2] : 2009年4月28日 0:00:00
// month--
arguments: [2009, 1, 1] : 2009年2月1日 0:00:00
arguments: [2009, 0, 1] : 2009年1月1日 0:00:00
arguments: [2009, -1, 1] : 2008年12月1日 0:00:00
arguments: [2009, -2, 1] : 2008年11月1日 0:00:00
// year--
arguments: [2009, 1, 1] : 2009年2月1日 0:00:00
arguments: [009, 1, 1] : 1909年2月1日 0:00:00
arguments: [09, 1, 1] : 1909年2月1日 0:00:00
arguments: [9, 1, 1] : 1909年2月1日 0:00:00
arguments: [0, 1, 1] : 1900年2月1日 0:00:00
arguments: [-1, 1, 1] : Mon Feb 1 00:00:00 UTC+0800 2 B.C.
arguments: [-2, 1, 1] : Sun Feb 1 00:00:00 UTC+0800 3 B.C.
arguments: [-3, 1, 1] : Sat Feb 1 00:00:00 UTC+0800 4 B.C.
arguments: [-2009, 1, 1] : Fri Feb 1 00:00:00 UTC+0800 2010 B.C.
运行环境:遨游 3.0.0.112 Alpha 3
// day--
arguments: [2009, 4, 1] : Fri May 01 2009 00:00:00 GMT+0800 (China Standard Time)
arguments: [2009, 4, 0] : Thu Apr 30 2009 00:00:00 GMT+0800 (China Standard Time)
arguments: [2009, 4, -1] : Wed Apr 29 2009 00:00:00 GMT+0800 (China Standard Time)
arguments: [2009, 4, -2] : Tue Apr 28 2009 00:00:00 GMT+0800 (China Standard Time)
// month--
arguments: [2009, 1, 1] : Sun Feb 01 2009 00:00:00 GMT+0800 (China Standard Time)
arguments: [2009, 0, 1] : Thu Jan 01 2009 00:00:00 GMT+0800 (China Standard Time)
arguments: [2009, -1, 1] : Mon Dec 01 2008 00:00:00 GMT+0800 (China Standard Time)
arguments: [2009, -2, 1] : Sat Nov 01 2008 00:00:00 GMT+0800 (China Standard Time)
// year--
arguments: [2009, 1, 1] : Sun Feb 01 2009 00:00:00 GMT+0800 (China Standard Time)
arguments: [009, 1, 1] : Mon Feb 01 1909 00:00:00 GMT+0800 (China Standard Time)
arguments: [09, 1, 1] : Mon Feb 01 1909 00:00:00 GMT+0800 (China Standard Time)
arguments: [9, 1, 1] : Mon Feb 01 1909 00:00:00 GMT+0800 (China Standard Time)
arguments: [0, 1, 1] : Thu Feb 01 1900 00:00:00 GMT+0800 (China Standard Time)
arguments: [-1, 1, 1] : Mon Feb 01 -1 00:00:00 GMT+0800 (China Standard Time)
arguments: [-2, 1, 1] : Sun Feb 01 -2 00:00:00 GMT+0800 (China Standard Time)
arguments: [-3, 1, 1] : Sat Feb 01 -3 00:00:00 GMT+0800 (China Standard Time)
arguments: [-2009, 1, 1] : Fri Feb 01 -2009 00:00:00 GMT+0800 (China Standard Time)
结论:1. 遨游 3.0.0.112 Alpha 3已不再用IE内核,更多遨游3.0信息请看这儿: http://bbs.maxthon.cn/forumdisplay.php?fid=130;
2. 火狐和遨游3.0不支持年为负值输入;
3. Date对象的toLocaleString() 方法在同一个浏览器中年为负无法转化为本地日期格式字符串,但是现实“BC”即公元前!;
4. 年为0是1900年;
5. 遨游 3.0.0.112 Alpha 3 toLocaleString()方法与预想中的有些出入 ;
最后:期待遨游 3.0