【问题标题】:timeZone issue for Expo AndroidExpo Android 的时区问题
【发布时间】:2021-09-17 12:35:57
【问题描述】:

似乎无论我使用什么包,timeZone RangeError: timeZone is not supported 与 Expo(v40) Android 似乎总是存在问题。我尝试添加 https://github.com/iamkun/dayjs/issues/1377#issuecomment-775991702 中提到的 polyfill,但意识到评论中还提到:

"This code is only usable if you do not use "toLocaleString" anywhere, except dayjs. It just fix dayjs, but can break other code (if it use toLocaleString method)."

我无法编辑应用程序 build.gradle,因为我正在使用 expo,所以对我可以在这里做什么有点困惑。有没有人提出解决方案?

当前设置:

"expo": "~40.0.0",
"expo-localization": "^10.2.0",
"date-fns": "^2.21.3",
"date-fns-tz": "^1.1.4",
"intl": "^1.2.5",

【问题讨论】:

  • pollyfill 看起来是个非常糟糕的主意,因为它取代了内置的 toLocaleString 方法。您需要显示产生错误的代码以及如何指定 timeZone

标签: javascript android date timezone expo


【解决方案1】:

好的,看来我找到了解决方案。我使用了这个 polyfill https://github.com/formatjs/date-time-format-timezone 并摆脱了 intl 包。现在 date-fns-tz 适用于 android 和 ios

【讨论】:

    猜你喜欢
    • 2021-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-24
    相关资源
    最近更新 更多