首页 > Web开发 > 详细

js 获取系统当前时间

时间:2018-02-07 12:51:02      阅读:215      评论:0      收藏:0      [点我收藏+]

js获取系统当前时间

CreateTime--2018年2月7日11:04:16

Author:Marydon

/**
 * 获取系统当前时间并格式化
 * @returns yyyy-MM-dd HH:mm:ss
 */
function getCurrentFormatDate() {
    // 系统当前时间格式化
    var currentFormatDate = "";
    // 获取系统当前日期
    var date = new Date();
    // 获取当前年
    var currentYear = date.getFullYear();
    // 获取当前月
    var currentMonth = date.getMonth() + 1;
    // 获取当前日
    var currentDay = date.getDate();
    //
    var currentHours = date.getHours();
    //
    var currentMinutes = date.getMinutes();
    //
    var currentSeconds = date.getSeconds();
    
    // 格式化
    if (currentMonth >= 1 && currentMonth <= 9) {
        currentMonth = "0" + currentMonth;
    }
    
    if (currentDay >= 0 && currentDay <= 9) {
        currentDay = "0" + currentDay;
    }

    currentFormatDate = currentYear + "-" + currentMonth + "-" + currentDay + " " + currentHours + ":" + currentMinutes
            + ":" + currentSeconds;
    return currentFormatDate;
}

 

js 获取系统当前时间

原文:https://www.cnblogs.com/Marydon20170307/p/8425667.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!