您的位置:首页 > Web前端 > JavaScript

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: