我想知道如何在jQuery中使用Date()函数以yyyy/mm/dd格式获取当前日期。


当前回答

console.log($.datepicker.formatDate('yy/mm/dd', new Date()));

其他回答

因为问题被标记为jQuery:

如果你也在使用jQuery UI,你可以使用$.datepicker.formatDate():

$.datepicker.formatDate('yy/mm/dd', new Date());

请看这个演示。

jQuery就是JavaScript。使用Javascript日期对象。

var d = new Date();
var strDate = d.getFullYear() + "/" + (d.getMonth()+1) + "/" + d.getDate();

var today = new Date(); var tday = getfullyear () + '/' + ( today.getMonth() < 9 ?'0': " ) + (today.getMonth() + 1) + '/' + ( getdate () < 10 ?'0': " ) + today.getDate(); console.log (tday);

function GetTodayDate() {
   var tdate = new Date();
   var dd = tdate.getDate(); //yields day
   var MM = tdate.getMonth(); //yields month
   var yyyy = tdate.getFullYear(); //yields year
   var currentDate= dd + "-" +( MM+1) + "-" + yyyy;

   return currentDate;
}

非常方便的功能使用,享受。你不需要任何javascript框架。它只是在简单的javascript工作。

关闭jQuery插件页面。所以手动:

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 );