码迷,mamicode.com
首页 > Web开发 > 详细

js 获取当前日期时间

时间:2018-08-16 13:43:48      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:als   日期时间   min   UNC   minutes   lse   tor   obj   lld   

function getCurrentDate(fulldate = false, separator = [-, :]) {
    let currentTimeObj = new Date();

    let year = currentTimeObj.getFullYear();
    let month = (currentTimeObj.getMonth() + 1);
    month = month >= 10 ? month : 0 + month;
    let day = currentTimeObj.getDate();
    day = day >= 10 ? day : 0 + day;
    let hour = currentTimeObj.getHours();
    hour = hour >= 10 ? hour : 0 + hour;
    let minute = currentTimeObj.getMinutes();
    minute = minute >= 10 ? minute : 0 + minute;
    let second = currentTimeObj.getSeconds();
    second = second >= 10 ? second : 0 + second;
    
    if (fulldate) {
        let ymd = [year, month, day];
        let his = [hour, minute, second];
        return ymd.join(separator[0]) +   + his.join(separator[1]);
    } else {
        let ymd = [year, month, day];
        return ymd.join(separator[0]);
    }
}

 

js 获取当前日期时间

标签:als   日期时间   min   UNC   minutes   lse   tor   obj   lld   

原文地址:https://www.cnblogs.com/nonsec/p/9486097.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!