美文网首页
获取当前时间

获取当前时间

作者: SangFall | 来源:发表于2018-06-29 12:07 被阅读0次
    // 获取当前时间
        function getNowFormatDate() {
            var date    = new Date();
            var year    = date.getFullYear(); //年
            var month   = date.getMonth() + 1; //月
            var day     = date.getDate(); //日
            var hour    = date.getHours(); //时
            var minute  = date.getMinutes(); //分
            var second  = date.getSeconds(); //秒
            if (month >= 1 && month <= 9) {
                month = "0" + month;
            }
            if (day >= 0 && day <= 9) {
                day = "0" + day;
            }
            if (hour >= 0 && hour <= 9) {
                hour = "0" + hour;
            }
            if (minute >= 0 && minute <= 9) {
                minute = "0" + minute;
            }
            if (second >= 0 && second <= 9) {
                second = "0" + second;
            }
            var currentdate = year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;
            return currentdate;
        }
    

    相关文章

      网友评论

          本文标题:获取当前时间

          本文链接:https://www.haomeiwen.com/subject/ukfayftx.html