如何解决“无效的时区”指定:... date-fns-tz反应本性错误?
我有一个由Expo SDK 45制成的移动应用程序,其主要功能与时代有关,
因此我选择使用 date-- fns 要管理和格式化应用程序中的时间...不幸的是,对于某个时区,format()
方法不会返回日历中选择的日期。
例如,在美国/纽约时区,如果我在日历中选择2022-06-23
,并且以form> format()
方法将其传递给我2022-06-22
但是,如果我进入欧洲/巴黎时区,一切都很好...
我做了一些研究,并遇到了 date-fns-tz ,这是对处理时区的支持。问题是,当我尝试使用formatintimezone()
方法时,我每次都会遇到此错误:指定的时区域无效:...'
,但我'确保我已经从文档中正确实施了代码...
即:
const { formatInTimeZone } = require('date-fns-tz')
const date = new Date('2014-10-25T10:46:20Z')
formatInTimeZone(date, 'America/New_York', 'yyyy-MM-dd HH:mm:ssXXX') // 2014-10-25 06:46:20-04:00
以上代码系统地返回错误...
I have a mobile application made with expo SDK 45, which its main feature is related to times,
So I opted to use date-fns to manage and format the time in the application... Unfortunately for some TimeZone, the format()
method does not return the date selected in the calendar.
For example, being in the United States/NewYork timeZone, if I select 2022-06-23
in the calendar and I pass it in the format()
method it gives me 2022-06-22
But if I enter in Europe/Paris timeZone everything works fine...
I did some research and came across date-fns-tz, which is a support for data-fns to handle timeZones. the problem, when I try to use the formatInTimeZone()
method for example, I get this error every time: 'Invalid time zone specified: ...'
But I'm sure I've implemented the code correctly from the documentation...
I.e:
const { formatInTimeZone } = require('date-fns-tz')
const date = new Date('2014-10-25T10:46:20Z')
formatInTimeZone(date, 'America/New_York', 'yyyy-MM-dd HH:mm:ssXXX') // 2014-10-25 06:46:20-04:00
The above code systematically returns an error...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我能够通过安装 date time-time-format-timezone 作为依赖关系,并从我的应用程序的根部导入它,
当前我的应用程序输入文件(app.tsx)看起来像这样:
I was able to solve my problem by installing date-time-format-timezone as a dependency and importing it from the root of my application
Currently my app entry file (App.tsx) looks like this: