您好,欢迎来到才安养生。
搜索
您的当前位置:首页javascript显示当前系统时间代码_时间日期

javascript显示当前系统时间代码_时间日期

来源:才安养生


1.在中加入下列代码
代码如下:

var timerID = null;
var timerRunning = false;
function stopclock (){
if(timerRunning)
clearTimeout(timerID);
timerRunning = false;}
function startclock () {
stopclock();
showtime();}
function showtime () {
var now = new Date();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds()
var timeValue = "" +((hours >= 12) ? "下午 " : "上午 " )
timeValue += ((hours >12) ? hours -12 :hours)
timeValue += ((minutes < 10) ? ":0" : ":") + minutes
timeValue += ((seconds < 10) ? ":0" : ":") + seconds
document.clock.thetime.value = timeValue;
timerID = setTimeout("showtime()",1000);
timerRunning = true;}


2.在中加入下列代码
onload=startclock()
3.在显示时间的位置插入下列代码,建议使用表格定位
[code]

//只获得当前系统日期的函数

document.write(new Date().getYear()+"-"+(new Date().getMonth()+1)+"-"+new Date().getDate());

http://www.gxlcms.com/article/12786.htm

Copyright © 2019- cagj.cn 版权所有

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务