博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
转自:http://www.feiesoft.com/00047/
<script type="text/javascript"> // JS Date当前时间获取方法在各浏览器中的差异 // 当前时间: var dt = new Date(); // Date([datetime])构造函数初始化对象时不输入参数 [datetime] ,则以用户本地电脑上的时间初始化 dt。 // dt 是一个 JS Date对象,在字符串环境下输出当前时间标准格式串,即此时自动调用 dt 对象的toString()方法(注:在JS中,任何对象都有一个 toString()方法,用于输出一些关于对象直观上的文本表述。)。 // 例: document.writeln(dt); document.writeln(dt.toString()); // 各浏览器输出: // // 微软 IE10 浏览器: Sat Nov 2 03:48:58 UTC+0800 2013 // 谷歌 Chrome 浏览器:Sat Nov 02 2013 04:07:03 GMT+0800 (中国标准时间) // 奇虎360安全浏览器:Sat Nov 02 2013 03:49:54 GMT+0800 (中国标准时间) // Firefox 25.0 火狐浏览器:Sat Nov 02 2013 03:55:02 GMT+0800 // //日期、时间 document.writeln(dt.toLocaleString()); // // 微软 IE10 浏览器: 2013年11月2日 4:15:55 // 谷歌 Chrome 浏览器:2013年11月2日 上午4:15:43 // 奇虎360安全浏览器:Sat Nov 02 2013 04:16:41 GMT+0800 (中国标准时间) // Firefox 25.0 火狐浏览器:2013年11月2日 4:18:30 // //在地日期: document.writeln(dt.toLocaleDateString()); // // 微软 IE10 浏览器: 2013年11月2日 // 谷歌 Chrome 浏览器:2013年11月2日 // 奇虎360安全浏览器:Saturday, November 02, 2013 // Firefox 25.0 火狐浏览器:2013年11月2日 // //在地时间: document.writeln(dt.toLocaleTimeString()); // // 微软 IE10 浏览器: 4:20:04 // 谷歌 Chrome 浏览器:上午4:20:06 // 奇虎360安全浏览器:04:20:08 // Firefox 25.0 火狐浏览器:04:20:08 // // 如果要得到“YYYY年MM月DD日 HH:mm:SS”格式的当前时间值,强烈推荐用: // document.writeln(dt.getFullYear() + "年" + dt.getMonth() + "月" + dt.getDate() + "日 " + dt.getHours() + ":" + dt.getMinutes() + ":" + dt.getSeconds()); </script>