js获取当前时间并以时钟显示
2012-11-01 17:18
429 查看
<script type="text/javascript">
window.onload = function getTime(){
var st = showtime();
//对文本框赋值
document.getElementById("clock").innerText= st;
//设置过1000毫秒就是1秒,调用showtime方法
setTimeout("getTime()",1000);
}
function showtime()
{
today=new Date();
var year=today.getYear();
var month=today.getMonth()+1;
var day=today.getDate();
var hours = today.getHours();
var minutes = today.getMinutes();
var seconds = today.getSeconds();
// liehuo.net
var timeValue1 = ((hours < 10) ? "0" : "") + hours+"";
timeValue1 += ((minutes < 10) ? ":0" : ":") + minutes+"";
timeValue1 += ((seconds < 10) ? ":0" : ":") + seconds+"";
var timeValue2 = year;
timeValue2 += ((month < 10) ? "-0" : "-") + month+"";
timeValue2 += ((day < 10) ? "-0" : "-") + day+"";
var timetext=timeValue2+" "+timeValue1
return timetext;
}
</script>
<label id="clock"></label>
window.onload = function getTime(){
var st = showtime();
//对文本框赋值
document.getElementById("clock").innerText= st;
//设置过1000毫秒就是1秒,调用showtime方法
setTimeout("getTime()",1000);
}
function showtime()
{
today=new Date();
var year=today.getYear();
var month=today.getMonth()+1;
var day=today.getDate();
var hours = today.getHours();
var minutes = today.getMinutes();
var seconds = today.getSeconds();
// liehuo.net
var timeValue1 = ((hours < 10) ? "0" : "") + hours+"";
timeValue1 += ((minutes < 10) ? ":0" : ":") + minutes+"";
timeValue1 += ((seconds < 10) ? ":0" : ":") + seconds+"";
var timeValue2 = year;
timeValue2 += ((month < 10) ? "-0" : "-") + month+"";
timeValue2 += ((day < 10) ? "-0" : "-") + day+"";
var timetext=timeValue2+" "+timeValue1
return timetext;
}
</script>
<label id="clock"></label>
相关文章推荐
- JS获取当前时间 格式 年月日 礼拜几 显示阴历日期 节气
- JS获取当前时间和星期几,并制作时钟效果 jquery
- js显示当前时间及其时钟显示
- easy UI中利用JS获取当前月的第一天和最后一天,并显示到时间控件上
- js实时获取并显示当前时间的方法
- js获取当前时间显示在页面上
- JS简单获取及显示当前时间的方法
- js获取当前日期时间同时显示星期
- js获取当前时间显示
- JS获取当前时间并显示
- js获取当前时间显示在页面上并每秒刷新
- js实时获取并显示当前时间的方法
- js获取当前时间 显示的格式类型2017-06-03 16:13:12
- js获取当前时间显示在页面上
- 使用js获取系统当前时间并在页面显示
- js实时获取并显示当前时间的方法
- 使用jQuery方法获取当前日期和时间!(时钟显示功能)
- js获取当前时间显示在页面上并每秒刷新
- Js获取当前日期时间及其它操作
- js动态显示当前日期,时间和星期代码