每一个你不满意的现在,都有一个你不努力的曾经. 网站首页 > js
获取当前时间精确到秒(闭包)
发布时间:2019-01-02 15:41:45 修改时间:2019-01-02 15:41:45 阅读:5172 评论:0 0
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <div id='time'></div> </body> <script> function whriteTime(){ console.log(getNowFormatDate()); document.getElementById('time').innerHTML = getNowFormatDate(); } setInterval(whriteTime,1000); function getNowFormatDate() { var date = new Date(); var seperator1 = "-"; var seperator2 = ":"; var month = date.getMonth() + 1; var strDate = date.getDate(); var strseconds = date.getSeconds(); if (month >= 1 && month <= 9) { month = "0" + month; } if (strDate >= 0 && strDate <= 9) { strDate = "0" + strDate; } if (strseconds >= 0 && strseconds <= 9) { strseconds = "0" + strseconds; } var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate + " " + date.getHours() + seperator2 + date.getMinutes() + seperator2 + strseconds; return currentdate; } </script> </html>
回复列表
关键字词:nbsp,style,gt,lt,var,amp