JS Date当前时间:获取日期时间方法在各浏览器中的差异
2024-08-28 18:59:36
转自: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>
最新文章
- 微软发布VSBT,无需安装Visual Studio即可实现项目编译
- 如何为Swift进行宏定义
- REST服务返回自定义的HttpResponseMessage
- SDAccel-FPGA将带来至多25倍单位功耗性能提升
- php——n维数组的遍历——递归
- POJ 1679 The Unique MST (次小生成树)
- Construct Binary Tree From Inorder and Preorder/Postorder Traversal
- Microsoft Deployment Toolkit 2013 Preview Release Now Available
- Hadoop集群的安装与配置(centos 6.5)
- HBase Rowkey 设计指南
- 转:Log Explorer使用说明恢复被误删除的数据
- Change upload file limit in specified Webapllication in SharePoint (PowerShell)
- Scala:HelloWorld
- js堆和栈
- 洛谷P2564 生日礼物【单调队列】
- Windows 平台安装 MongoDB
- Hadoop集群维护
- [C#]INI文件控制类
- 用SQL查询方式显示GROUP BY中的TOP解决方法[转]
- 早该知道的7个JavaScript技巧