首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >斯威夫特:为什么DateComponentsFormatter.localizedString(from:unitsStyle:)工作日不工作?

问斯威夫特:为什么DateComponentsFormatter.localizedString(from:unitsStyle:)工作日不工作?
EN

Stack Overflow用户
提问于 2022-02-05 21:48:01
回答 1查看 71关注 0票数 -1

为什么DateComponentsFormatter.localizedString(from:unitsStyle:)不适用于weekday

代码语言:javascript
复制
let twoDays = DateComponents(day: 2)
let threeWeeks = DateComponents(weekday: 3)

DateComponentsFormatter.localizedString(from: twoDays, unitsStyle: .full) ?? "found nil" // "2 days"
DateComponentsFormatter.localizedString(from: threeWeeks, unitsStyle: .full) ?? "found nil" // returns "found nil"
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-02-05 22:03:45

DateComponents有一个名为allowedUnits的属性,weekday不是一个合法单位。

获准的单位如下:

年月weekOfMonth日小时分秒

看这个参考。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71002428

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档