源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

JS简单获取及显示当前时间的方法

  • 时间:2020-03-25 00:24 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:JS简单获取及显示当前时间的方法
本文实例讲述了JS简单获取及显示当前时间的方法。分享给大家供大家参考,具体如下:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>当前时间</title>
</head>
<body>
 <script>
var now = new Date();
var year = now.getFullYear();    //年
var month = now.getMonth() + 1;   //月
var day = now.getDate();      //日
var hh = now.getHours();      //时
var mm = now.getMinutes();     //分
var clock = year + "-";
if (month < 10)
clock += "0";
clock += month + "-";
if (day < 10)
clock += "0";
clock += day + " ";
if (hh < 10)
clock += "0";
clock += hh + ":";
if (mm < 10) clock += '0';
clock += mm;
document.write(clock);
</script>
</body>
</html>

[b]PS:对JavaScript时间与日期操作感兴趣的朋友还可以参考本站在线工具:[/b] Unix时间戳(timestamp)转换工具: [url=http://tools.jb51.net/code/unixtime]http://tools.jb51.net/code/unixtime[/url] 在线世界各地时间查询: [url=http://tools.jb51.net/zhuanhuanqi/worldtime]http://tools.jb51.net/zhuanhuanqi/worldtime[/url] 在线万年历日历: [url=http://tools.jb51.net/bianmin/wannianli]http://tools.jb51.net/bianmin/wannianli[/url] 网页万年历日历: [url=http://tools.jb51.net/bianmin/webwannianli]http://tools.jb51.net/bianmin/webwannianli[/url] 更多关于JavaScript相关内容可查看本站专题:《[url=http://www.1sucai.cn/Special/321.htm]JavaScript时间与日期操作技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/502.htm]JavaScript切换特效与技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/472.htm]JavaScript查找算法技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/462.htm]JavaScript动画特效与技巧汇总[/url]》、《[url=http://www.1sucai.cn/Special/439.htm]JavaScript错误与调试技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/297.htm]JavaScript数据结构与算法技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/281.htm]JavaScript遍历算法与技巧总结[/url]》及《[url=http://www.1sucai.cn/Special/119.htm]JavaScript数学运算用法总结[/url]》 希望本文所述对大家JavaScript程序设计有所帮助。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部