使用 Hermes JS 引擎时返回无效日期的时刻

sak*_*a73 3 momentjs react-native moment-timezone react-native-hermes

当我使用jsc引擎时,一切工作正常,但是当我在反应本机应用程序中从jsc引擎切换到Hermes引擎时,我开始在使用时刻时收到无效日期。

代码:

const defaultDate = moment(currentTimeStamp).format("YYYY/MM/DD"); //till this it works fine
return moment(defaultDate).toDate().getTime(); // throws INVALID DATE
Run Code Online (Sandbox Code Playgroud)

sak*_*a73 5

经过一番研究,我自己解决了这个问题,所以我想在这里分享一下。

解决方案1:

而不是使用像format("YYYY/MM/DD");. 像这样使用它,format("YYYY-MM-DD");因为这是时刻可以理解的标准格式之一。

解决方案2:

如果您只需要该格式(这是我的情况)。您需要立即告知您正在使用的格式。像这样:

return moment(defaultDate,"YYYY/MM/DD").toDate().getTime();
Run Code Online (Sandbox Code Playgroud)