How to get current date in jquery?

前端 未结 30 1931
春和景丽
春和景丽 2020-11-27 09:51

I want to know how to use the Date() function in jQuery to get the current date in a yyyy/mm/dd format.

30条回答
  •  孤街浪徒
    2020-11-27 10:09

    The jQuery plugin page is down. So manually:

    function strpad00(s)
    {
        s = s + '';
        if (s.length === 1) s = '0'+s;
        return s;
    }
    
    var now = new Date();
    var currentDate = now.getFullYear()+ "/" + strpad00(now.getMonth()+1) + "/" + strpad00(now.getDate());
    console.log(currentDate );
    

提交回复
热议问题