如何在没有此错误的情况下将 unix 日期传递给时刻 js:"Deprecation warning: value provided is not in a recognized RFC2822 or



我通读了所有其他类似的问题,但仍然找不到解决问题的方法。

我在节点中有一个应用程序.js它使用时刻.js。

(1st( 应用程序通过对 API 的 HTTP 请求getUNIX 日期,然后 (2nd( 将其传递给 moment.js

如下所示
const contractEndDate = 1619740800000;
const readablecontractEndDate = moment(`${contractEndDate}`, "x").format("dddd, MMMM Do YYYY, h:mm:ss a");
const preparationPeriod = 90;
const taskDate = moment.utc(contractEndDate).subtract(preparationPeriod, 'days').valueOf();
const readableTaskDate = moment(taskDate).format("dddd, MMMM Do YYYY, h:mm:ss a");
console.log(`contract end date is ${readablecontractEndDate} and task date is ${taskDate} or ${readableTaskDate}`)
/*Output: Deprecation warning: value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), which is not reliable across all browsers and versions. Non RFC2822/ISO date formats are discouraged and will be removed in an upcoming major release. Please refer to http://momentjs.com/guides/#/warnings/js-date/ for more info.
Arguments: 
2020-01-15T22:17:30.182889+00:00 app[web.1]: [0] _isAMomentObject: true, _isUTC: true, _useUTC: true, _l: undefined, _i: 1619740800000, _f: undefined, _strict: undefined, _locale: [object Object]
*/

它在此代码笔中工作正常:

https://codepen.io/lumi/pen/bxrjZw?editors=0011

但是我不明白为什么当我运行我的应用程序时它不起作用。

我真的不明白为什么,但是在相同的代码工作没有任何错误的第二天

const contractEndDate = 1619740800000;
const readablecontractEndDate = moment(`${contractEndDate}`, "x").format("dddd, MMMM Do YYYY, h:mm:ss a");
const preparationPeriod = 90;
const taskDate = moment.utc(contractEndDate).subtract(preparationPeriod, 'days').valueOf();
const readableTaskDate = moment(taskDate).format("dddd, MMMM Do YYYY, h:mm:ss a");
console.log(`contract end date is ${readablecontractEndDate} and task date is ${taskDate} or ${readableTaskDate}`)

相关内容

最新更新