js获取当前的时间显示的是24小时的时间吗
展开全部
JS获取的是本地电脑的日期时间格式,每个人电脑设置不一样,不一定都是24小时时间格式的。不过你可以用JS代码写输出成24小时时间格式。代码如下:
当前时间为:<span id="now"></span>
<script type="text/javascript">
//动态显示年月日时间和周几【凌陈亮(QQ:57404811)】
//显示当前时间的对象ID
gw_now('now');
function gw_now(id){
var obj=window.document.getElementById(id);
var date=new Date();
var year=date.getFullYear();
var month=gw_now_addzero(date.getMonth()+1);
var day=gw_now_addzero(date.getDate());
var hour=gw_now_addzero(date.getHours());
var minute=gw_now_addzero(date.getMinutes());
var second=gw_now_addzero(date.getSeconds());
switch (date.getDay()) {
case 0:week="星期天";break
case 1:week="星期一";break
case 2:week="星期二";break
case 3:week="星期三";break
case 4:week="星期四";break
case 5:week="星期五";break
case 6:week="星期六";break
}
obj.innerHTML=year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second + " " + week;
setTimeout("gw_now('" + id + "')",1000);
}
function gw_now_addzero(temp){
if(temp<10) return "0" + temp;
else return temp;
}
</script>
当前时间为:<span id="now"></span>
<script type="text/javascript">
//动态显示年月日时间和周几【凌陈亮(QQ:57404811)】
//显示当前时间的对象ID
gw_now('now');
function gw_now(id){
var obj=window.document.getElementById(id);
var date=new Date();
var year=date.getFullYear();
var month=gw_now_addzero(date.getMonth()+1);
var day=gw_now_addzero(date.getDate());
var hour=gw_now_addzero(date.getHours());
var minute=gw_now_addzero(date.getMinutes());
var second=gw_now_addzero(date.getSeconds());
switch (date.getDay()) {
case 0:week="星期天";break
case 1:week="星期一";break
case 2:week="星期二";break
case 3:week="星期三";break
case 4:week="星期四";break
case 5:week="星期五";break
case 6:week="星期六";break
}
obj.innerHTML=year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second + " " + week;
setTimeout("gw_now('" + id + "')",1000);
}
function gw_now_addzero(temp){
if(temp<10) return "0" + temp;
else return temp;
}
</script>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询