我想知道如何在jQuery中使用Date()函数以yyyy/mm/dd格式获取当前日期。
当前回答
我知道我迟到了,但这就是你所需要的
var date = (new Date()).toISOString().split('T')[0];
toISOString()使用javascript的内置函数。
cd = (new Date()).toISOString().split('T')[0]; console.log (cd); 警报(cd);
其他回答
关闭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 );
var today = new Date(); var tday = getfullyear () + '/' + ( today.getMonth() < 9 ?'0': " ) + (today.getMonth() + 1) + '/' + ( getdate () < 10 ?'0': " ) + today.getDate(); console.log (tday);
这一行语句将给出YYYY-MM-DD:
new Date().toISOString().substr(0, 10)
'2022-06-09'
你可以这样做:
var now = new Date();
dateFormat(now, "dddd, mmmm dS, yyyy, h:MM:ss TT");
// Saturday, June 9th, 2007, 5:46:21 PM
或者类似的东西
var dateObj = new Date();
var month = dateObj.getUTCMonth();
var day = dateObj.getUTCDate();
var year = dateObj.getUTCFullYear();
var newdate = month + "/" + day + "/" + year;
alert(newdate);
var d = new Date();
var today = d.getFullYear() + '/' + ('0'+(d.getMonth()+1)).slice(-2) + '/' + ('0'+d.getDate()).slice(-2);