获取当前XXXX-XX-XX格式的日期

function getDate () {
    var newDate = new Date(),
        Year = newDate.getFullYear(),
        Month = newDate.getMonth() + 1,
        Day = newDate.getDate(),
        nowDate = '';
    
    if (Month >= 1 && Month <= 9) {
        Month = "0" + Month;
    }

     if (Day >= 1 && Day <= 9) {
        Day = "0" + Day;
    }

    return nowDate = Year + '-' + Month + '-' + Day;
}

借鉴过来的,感觉是比较淳朴的方法

发布了19 篇原创文章 · 获赞 6 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/heyNewbie/article/details/105436324
xx
今日推荐