js显示当前系统时间的代码分享
发布时间:2014-12-18 编辑:jiaochengji.com
本文介绍下,用js实现显示当前系统时间的一段代码,供大家学习参考。
1,js获取当前系统时间
<script> /** * js显示当前系统时间 * edit www.jbxue.com */ var myDate = new Date(); myDate.getYear(); //获取当前年份(2位) myDate.getFullYear(); //获取完整的年份(4位,1970-????) myDate.getMonth(); //获取当前月份(0-11,0代表1月) myDate.getDate(); //获取当前日(1-31) myDate.getDay(); //获取当前星期X(0-6,0代表星期天) myDate.getTime(); //获取当前时间(从1970.1.1开始的毫秒数) myDate.getHours(); //获取当前小时数(0-23) myDate.getMinutes(); //获取当前分钟数(0-59) myDate.getSeconds(); //获取当前秒数(0-59) myDate.getMilliseconds(); //获取当前毫秒数(0-999) myDate.toLocaleDateString(); //获取当前日期 var mytime=myDate.toLocaleTimeString(); //获取当前时间 myDate.toLocaleString( ); //获取日期与时间 </script>
2,js显示当前系统时间的完整代码
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>显示当前系统时间_www.jbxue.com</title> <script language="javascript" type="text/javascript"> <!-- //获得当前时间,刻度为一千分一秒 var initializationTime=(new Date()).getTime(); function showLeftTime() { var now=new Date(); var year=now.getYear(); var month=now.getMonth(); var day=now.getDate(); var hours=now.getHours(); var minutes=now.getMinutes(); var seconds=now.getSeconds(); document.all.show.innerHTML=""+year+"年"+month+"月"+day+"日 "+hours+":"+minutes+":"+seconds+""; //一秒刷新一次显示时间 var timeID=setTimeout(showLeftTime,1000); } //--> </script> </head> <body onload="showLeftTime()"> <label id="show">显示时间的位置</label> </body> </html>
您可能感兴趣的文章:
js显示当前系统时间的代码分享
js实时获取系统当前时间并显示的代码分享
js获取当前时间 js获取时刻变化的时间
js获取当前系统时间实例代码
Js页面时间实时更新的实现代码
php 获取今日、昨日、上周、本月的起始与结束时间戳
php获取本周、本月第一天与最后一天的时间戳
javascript打印当前时间的示例代码
PHP实现时间轴函数(刚刚、5分钟前)
js获取当前时间戳与日期比较
[关闭]