【发布时间】:2021-11-02 14:35:21
【问题描述】:
我有以下几点:
const input: string = '2021-11-2T10:20:00+01:00';
const date: string = moment( input ).format('YYYY-MM-DD');
const time: string = moment( input ).format('HH:mm');
请有人告诉我为什么“日期”和“时间”都返回“无效日期”?
据我了解,“输入”字符串是标准日期格式(moment 给了我这种格式)。
【问题讨论】:
-
我在momentjs.com 上将此代码粘贴到我的控制台中,但没有收到此错误。我刚得到这个:
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. Please refer to http://momentjs.com/guides/#/warnings/js-date/ for more info. -
嗯。我刚刚做了
moment().format();并使用返回的这个值作为“输入”值,它可以工作。我想我使用的日期有问题。 -
让我推荐 luxon 库。如果时刻应该关键地打破,那是一个很好的选择。
标签: javascript typescript momentjs