gpt4 book ai didi

javascript - 为什么 toLocaleDateString 不能在 react native (Android)中工作?

转载 作者:行者123 更新时间:2023-12-03 07:23:21 27 4
gpt4 key购买 nike

由于一些奇怪的原因,toLocaleDateString 在react-native 中无法正常工作。有时有效,有时无效。对于以下代码,

const dateString = this.state.date.toLocaleDateString('en-US', {
weekday: 'short',
day: 'numeric',
month: 'long',
year: 'numeric',
});

有时我只得到07/17/2018,有时是常规输出。现在我可以自己实现它或使用 moment.js 或类似的东西。我想知道为什么会有这样的行为。

最佳答案

React Native 在非 Debug模式下使用 JavaScriptCore 引擎,它不能很好地处理日期,但在调试期间可以工作,因为它在调试时使用 chrome V8 引擎。

所以最好使用momentXDate JavaScript 库。

关于javascript - 为什么 toLocaleDateString 不能在 react native (Android)中工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51399551/

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