首页 > 代码库 > javascript显示年月日时间代码显示电脑时间
javascript显示年月日时间代码显示电脑时间
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>显示当前北京时间</title> <script language=Javascript> function time() { //获得显示时间的div t_div = document.getElementById(‘showtime‘); var now = new Date() //替换div内容 t_div.innerHTML = "现在是" + now.getFullYear() + "年" + (now.getMonth() + 1) + "月" + now.getDate() + "日" + now.getHours() + "时" + now.getMinutes() + "分" + now.getSeconds() + "秒"; //等待一秒钟后调用time方法,由于settimeout在time方法内,所以可以无限调用 setTimeout(time, 1000); } </script> </head> <body onload="time()"> <div id="showtime"></div> </body> </html>
效果图:
javascript显示年月日时间代码显示电脑时间
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。