S.j*_*kib 6 javascript date react-native
由于某些奇怪的原因,toLocaleDateStringreact-native无法正常工作。有时它起作用,有时却不起作用。对于以下代码,
const dateString = this.state.date.toLocaleDateString('en-US', {
            weekday: 'short',
            day: 'numeric',
            month: 'long',
            year: 'numeric',
        });
有时我得到公正的07/17/2018输出,有时得到正常的输出。现在,我可以自己实现它,也可以使用moment.js类似的东西。我想知道为什么会这样。
我目前"react-native": "~0.63.3",在使用 toLocaleDateString 时遇到同样的问题。这是为我解决的问题:
在我的 android/app/build.gradle 文件中,我替换了以下行
def jscFlavor = 'org.webkit:android-jsc:+' //remove this - it might be something else depending on your react-native version, try to look in your build.gradle file for similar comment I posted below in the picture
和
def jscFlavor = 'org.webkit:android-jsc-intl:+' // add this
在这里找到解决方案:https ://github.com/react-community/jsc-android-buildscripts#international-variant
在我的 build.gradle 文件中,有一条来自 react-native 的评论,描述了该问题
| 归档时间: | 
 | 
| 查看次数: | 2636 次 | 
| 最近记录: |