我想知道如何在jQuery中使用Date()函数以yyyy/mm/dd格式获取当前日期。
当前回答
console.log($.datepicker.formatDate('yy/mm/dd', new Date()));
其他回答
你也可以用moment.js实现这一点。 在你的html中包含moment.js。
<script src="moment.js"></script>
并在脚本文件中使用下面的代码来获得格式化日期。
moment(new Date(),"YYYY-MM-DD").utcOffset(0, true).format();
关闭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);
我知道我迟到了,但这就是你所需要的
var date = (new Date()).toISOString().split('T')[0];
toISOString()使用javascript的内置函数。
cd = (new Date()).toISOString().split('T')[0]; console.log (cd); 警报(cd);
在JavaScript中,你可以使用date对象获取当前日期和时间;
var now = new Date();
这将获得本地客户端机器时间
jquery示例LINK
如果你正在使用jQuery DatePicker,你可以应用它在任何文本框,像这样:
$( "#datepicker" ).datepicker({dateFormat:"yy/mm/dd"}).datepicker("setDate",new Date());