JS动态加载当前时间的方法
作者:bea
本文实例讲述了JS动态加载当前时间的方法。分享给大家供大家参考。具体实现方法如下: <body bgcolor="#fef4d9" onload ="time()"> <script language="JavaScript">function time () { var now = new Date(); var yr = now.getYear(); var mName = now.getMonth() + 1; var dName
本文实例讲述了JS动态加载当前时间的方法。分享给大家供大家参考。具体实现方法如下:
<body bgcolor="#fef4d9" onload ="time()">
<script language="JavaScript">
function time ()
{
var now = new Date();
var yr = now.getYear();
var mName = now.getMonth() + 1;
var dName = now.getDay() + 1;
var dayNr = ((now.getDate()<10) ? "0" : "")+ now.getDate();
var ampm = (now.getHours() >= 12) ? " PM" : " AM"
var hours = now.getHours();
hours = ((hours > 12) ? hours - 12 : hours);
var minutes = ((now.getMinutes() < 10) ? ":0" : ":") + now.getMinutes();
var seconds = ((now.getSeconds() < 10) ? ":0" : ":") + now.getSeconds();
if(dName==1) Day = "星期日";
if(dName==2) Day = "星期一";
if(dName==3) Day = "星期二";
if(dName==4) Day = "星期三";
if(dName==5) Day = "星期四";
if(dName==6) Day = "星期五";
if(dName==7) Day = "星期六";
if(mName==1) Month="1月";
if(mName==2) Month="2月";
if(mName==3) Month="3月";
if(mName==4) Month="4月";
if(mName==5) Month="5月";
if(mName==6) Month="6月";
if(mName==7) Month="7月";
if(mName==8) Month="8月";
if(mName==9) Month="9月";
if(mName==10) Month="10月";
if(mName==11) Month="11月";
if(mName==12) Month="12月";
var DayDateTime=(yr+ "年"+" "+ Month+ dayNr+ "日"+ Day+ " "
+ hours+ minutes+ seconds+ " "+ ampm
);
document.getElementById ("face").innerText=DayDateTime ;
timerID = setTimeout("time()",1000);
}
</script>
<form id ="form">
<div>
<asp:Label ID ="face" runat ="server" ></asp:Label>
</div>
</form>
</body>
希望本文所述对大家的javascript程序设计有所帮助。
猜你喜欢
您可能感兴趣的文章:
- Node.js抓取中文网页乱码问题和解决方法
- JS数组的常见用法实例
- bootstrap table 服务器端分页例子分享
- js实现对table动态添加、删除和更新的方法
- js+css实现导航效果实例
- jquery.mobile 共同布局遇到的问题小结
- jquery中EasyUI使用技巧小结
- javascript操作符"!~"详解
- JavaScript中的标签语句用法分析
- jquery动态添加删除(tr/td)
- javascript模拟map输出与去除重复项的方法
- JavaScript设置body高度为浏览器高度的方法
- jquery动态改变div宽度和高度
- angularJS结合canvas画图例子
- jquery实现上下左右滑动的方法
- js实现上传图片预览的方法
- js实现ifram取父窗口URL地址的方法
- jquery实现相册一下滑动两次的方法
- js点击选择文本的方法