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


当前回答

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

其他回答

var d = new Date();
var month = d.getMonth() + 1;
var day = d.getDate();
var year = d.getYear();
var today = (day<10?'0':'')+ day + '/' +(month<10?'0':'')+ month + '/' + year;
alert(today);

看到这个。 $.now()方法是表达式(new Date). gettime()返回的数字的简写。

你可以使用下面的代码:

var nowDate     = new Date();
var nowDay      = ((nowDate.getDate().toString().length) == 1) ? '0'+(nowDate.getDate()) : (nowDate.getDate());
var nowMonth    = ((nowDate.getMonth().toString().length) == 1) ? '0'+(nowDate.getMonth()+1) : (nowDate.getMonth()+1);
var nowYear     = nowDate.getFullYear();
var formatDate  = nowDay + "." + nowMonth + "." + nowYear;

你可以在这里找到一个工作演示

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

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

试试这个…

var d = new Date();
alert(d.getFullYear()+'/'+(d.getMonth()+1)+'/'+d.getDate());

getMonth()返回月份0到11,因此我们希望添加1来表示准确的月份

参考:https://www.w3schools.com/jsref/jsref_obj_date.asp