手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >JS简单获取及显示当前时间的方法
JS简单获取及显示当前时间的方法
摘要:本文实例讲述了JS简单获取及显示当前时间的方法。分享给大家供大家参考,具体如下:当前时间varnow=newDate();varyear=n...

本文实例讲述了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>

PS:对JavaScript时间与日期操作感兴趣的朋友还可以参考本站在线工具:

Unix时间戳(timestamp)转换工具:

http://tools.jb51.net/code/unixtime

在线世界各地时间查询:

http://tools.jb51.net/zhuanhuanqi/worldtime

在线万年历日历:

http://tools.jb51.net/bianmin/wannianli

网页万年历日历:

http://tools.jb51.net/bianmin/webwannianli

希望本文所述对大家JavaScript程序设计有所帮助。

【JS简单获取及显示当前时间的方法】相关文章:

jquery简单实现外部链接用新窗口打开的方法

JavaScript获取当前运行脚本文件所在目录的方法

JavaScript获得url查询参数的方法

javascript实现点击后变换按钮显示文字的方法

JavaScript实现鼠标拖动效果的方法

JQuery使用index方法获取Jquery对象数组下标的方法

Jquery实现动态切换图片的方法

jQuery子窗体取得父窗体元素的方法

jquery控制表单输入框显示默认值的方法

JavaScript实现DIV层拖动及动态增加新层的方法

精品推荐
分类导航