gpt4 book ai didi

javascript - 弃用警告 : moment construction falls back to js Date when I use moment. js 获取当前日期

转载 作者:行者123 更新时间:2023-12-03 08:58:25 26 4
gpt4 key购买 nike

我使用 moment.js 来获取当前日期。这是代码:

$(document).ready(function() {
var date = moment().format("YYYY/MM/DD");
console.log(date);
$('#calendar').fullCalendar({
theme: true,
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
defaultDate: date,
editable: true,
eventLimit: true // allow "more" link when too many event
});

});

我在控制台中获取当前日期以及此警告:

Deprecation warning: moment construction falls back to js Date. This is discouraged and will be removed in upcoming major release. Please refer to https://github.com/moment/moment/issues/1407 for more info.  

所以我添加了这样的 ISO 标签:

var date = moment().format("YYYY/MM/DD", "ddd, YYYY MM DD HH:mm:ss ZZ");  

但我收到了同样的警告。我怎样才能删除这个警告?

最佳答案

使用上面的代码我没有收到警告。我能够使用不同的语法引发警告:

// does not generate warning
var date1 = moment().format("YYYY/MM/DD");
console.log(date1);

// generates warning
var date2 = moment("YYYY/MM/DD");
console.log(date2);

http://plnkr.co/edit/zHvLm3XPkWKLSRI50UON

关于javascript - 弃用警告 : moment construction falls back to js Date when I use moment. js 获取当前日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32392725/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com