使用格式的 Momentjs 弃用警告
Momentjs Deprecation Warning using Format
我想知道上述已弃用的方法对我的 momentJS 方法意味着什么,以及我可以进行哪些更改以正确格式化我的值。我有这样格式的日期值 2015-12-11 00:00:00
。我正在尝试将它们转换为正确的字段格式 YYYY-MM-DD
。我下面的 jQuery 允许我以正确的格式转换我的日期值,没有任何问题,但我在控制台日志中收到以下警告。知道这是什么意思吗?
jQuery:
<script type="text/javascript">
$(document).ready(function() {
$("#test-form-date").val( moment("{{test.testDate}}").format('YYYY-MM-DD') );
$("#data-date-start").val( moment("{{test.testDateStart}}").format('YYYY-MM-DD') );
$("#data-date-end").val( moment("{{test.testDateEnd}}").format('YYYY-MM-DD') );
});
</script>
这是正在修改的表格:
<div class="test-form-header">
<input type="date" name="testDate" id="test-form-date" value="{{test.testDate}}">
</div>
</br>
<div class="form-inline date-start">
<label for="data-start-range">Data Date Start:</label>
<input type="date" id="data-date-start" name="dataDateStart" value="{{test.dataDateStart}}">
</div>
<div class="form-inline date-end">
<label for="data-end-range">Data Date End:</label>
<input type="date" id="data-date-end" name="dataDateEnd" value="{{test.dataDateEnd}}">
</div>
这是对控制台日志的警告:
The specified value "Sun Dec 27 2015 19:00:00 GMT-0500 (EST)" does not
conform to the required format, "yyyy-MM-dd". 10:60 The specified
value "Wed Sep 30 2015 20:00:00 GMT-0400 (EDT)" does not conform to
the required format, "yyyy-MM-dd". 10:64 The specified value "Thu Dec
03 2015 19:00:00 GMT-0500 (EST)" does not conform to the required
format, "yyyy-MM-dd". moment.js:737 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.
错误
at Function.createFromInputFallback (http://momentjs.com/downloads/moment.js:746:36)
at configFromString (http://momentjs.com/downloads/moment.js:826:32)
at configFromInput (http://momentjs.com/downloads/moment.js:1353:13)
at prepareConfig (http://momentjs.com/downloads/moment.js:1340:13)
at createFromConfig (http://momentjs.com/downloads/moment.js:1307:44)
at createLocalOrUTC (http://momentjs.com/downloads/moment.js:1385:16)
at local__createLocal (http://momentjs.com/downloads/moment.js:1389:16)
at utils_hooks__hooks (http://momentjs.com/downloads/moment.js:16:29)
at HTMLDocument.<anonymous> (http://localhost:3000/app/edit/10:87:38)
at j
(https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js:2:26925)
将此添加到您的代码中。
moment.createFromInputFallback = function(config) {
// unreliable string magic, or
config._d = new Date(config._i);
};
$("#test-form-date").val( moment("{{test.testDate}}").format('YYYY-MM-DD') );
错误发生是因为,
moment construction using a non-iso string is deprecated.
我想知道上述已弃用的方法对我的 momentJS 方法意味着什么,以及我可以进行哪些更改以正确格式化我的值。我有这样格式的日期值 2015-12-11 00:00:00
。我正在尝试将它们转换为正确的字段格式 YYYY-MM-DD
。我下面的 jQuery 允许我以正确的格式转换我的日期值,没有任何问题,但我在控制台日志中收到以下警告。知道这是什么意思吗?
jQuery:
<script type="text/javascript">
$(document).ready(function() {
$("#test-form-date").val( moment("{{test.testDate}}").format('YYYY-MM-DD') );
$("#data-date-start").val( moment("{{test.testDateStart}}").format('YYYY-MM-DD') );
$("#data-date-end").val( moment("{{test.testDateEnd}}").format('YYYY-MM-DD') );
});
</script>
这是正在修改的表格:
<div class="test-form-header">
<input type="date" name="testDate" id="test-form-date" value="{{test.testDate}}">
</div>
</br>
<div class="form-inline date-start">
<label for="data-start-range">Data Date Start:</label>
<input type="date" id="data-date-start" name="dataDateStart" value="{{test.dataDateStart}}">
</div>
<div class="form-inline date-end">
<label for="data-end-range">Data Date End:</label>
<input type="date" id="data-date-end" name="dataDateEnd" value="{{test.dataDateEnd}}">
</div>
这是对控制台日志的警告:
The specified value "Sun Dec 27 2015 19:00:00 GMT-0500 (EST)" does not conform to the required format, "yyyy-MM-dd". 10:60 The specified value "Wed Sep 30 2015 20:00:00 GMT-0400 (EDT)" does not conform to the required format, "yyyy-MM-dd". 10:64 The specified value "Thu Dec 03 2015 19:00:00 GMT-0500 (EST)" does not conform to the required format, "yyyy-MM-dd". moment.js:737 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.
错误
at Function.createFromInputFallback (http://momentjs.com/downloads/moment.js:746:36) at configFromString (http://momentjs.com/downloads/moment.js:826:32) at configFromInput (http://momentjs.com/downloads/moment.js:1353:13) at prepareConfig (http://momentjs.com/downloads/moment.js:1340:13) at createFromConfig (http://momentjs.com/downloads/moment.js:1307:44) at createLocalOrUTC (http://momentjs.com/downloads/moment.js:1385:16) at local__createLocal (http://momentjs.com/downloads/moment.js:1389:16) at utils_hooks__hooks (http://momentjs.com/downloads/moment.js:16:29) at HTMLDocument.<anonymous> (http://localhost:3000/app/edit/10:87:38) at j
(https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js:2:26925)
将此添加到您的代码中。
moment.createFromInputFallback = function(config) {
// unreliable string magic, or
config._d = new Date(config._i);
};
$("#test-form-date").val( moment("{{test.testDate}}").format('YYYY-MM-DD') );
错误发生是因为,
moment construction using a non-iso string is deprecated.