如何在
我想存储一个 DateTimeFormatOptions
供 date.toLocaleString()
在我的应用程序的多个位置使用。我将其定义为:
export const timeFormat = { month: 'numeric', day: '2-digit', hour: '2-digit', minute: '2-digit', hour12: false, timeZoneName: 'short', time Zone: 'UTC'}
我得到:
Argument of type '{ month: string; day: string; hour: string; minute: string; hour12: boolean; timeZoneName: string; timeZone: string; }' is not assignable to parameter of type 'DateTimeFormatOptions'.
Types of property 'month' are incompatible.
Type 'string' is not assignable to type '"numeric" | "2-digit" | "short" | "long" | "narrow" | undefined'.
但我无法弄清楚 import DateTimeFormatOptions。最终我只是编写了一个格式化日期的辅助方法,但我仍然可能需要导入它,因为我可能允许用户更改日期首选项。
I want to store a DateTimeFormatOptions
for date.toLocaleString()
to use in multiple places in my app. I defined it like:
export const timeFormat = { month: 'numeric', day: '2-digit', hour: '2-digit', minute: '2-digit', hour12: false, timeZoneName: 'short', time Zone: 'UTC'}
And I get:
Argument of type '{ month: string; day: string; hour: string; minute: string; hour12: boolean; timeZoneName: string; timeZone: string; }' is not assignable to parameter of type 'DateTimeFormatOptions'.
Types of property 'month' are incompatible.
Type 'string' is not assignable to type '"numeric" | "2-digit" | "short" | "long" | "narrow" | undefined'.
But I can't figure out import DateTimeFormatOptions. Eventually I just wrote a helper method that formats the date, but I still may need to import it because I may allow the user to change date preferences.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它位于
Intl
对象。您不需要导入它。只需将类型设置为Intl.DateTimeFormatOptions
即可。It's in the
Intl
object. You won't need to import it. Just set the type toIntl.DateTimeFormatOptions
.