js 获取系统当前时间
2016-10-23 10:50
330 查看
//获取系统当前时间 function getNowDate() { var date = new Date(); var month = date.getMonth() + 1; var strDate = date.getDate(); if (month >= 1 && month <= 9) { month = "0" + month; } if (strDate >= 0 && strDate <= 9) { strDate = "0" + strDate; } var minutes = date.getMinutes(); //因为getMinutes()方返回的分钟数如果小于10 的话不会以“10:03:56”的格式返回,而是“10:3:56”。所以要做个判断 if(minutes < 10){ minutes = "0" + minutes; } var currentdate = date.getFullYear() + "-" + month + "-" + strDate + " " + date.getHours() + ":" + minutes + ":" + date.getSeconds(); return currentdate; }
相关文章推荐