js 获取系统当前时间

来源:互联网 发布:埃勒里奎因知乎 编辑:程序博客网 时间:2024/05/17 05:19
//获取系统当前时间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;}
0 0
原创粉丝点击