DateFormatterConstructor
这是一个简单的 DateFormatter 扩展,允许您使用一行代码创建一个具有特定日期格式的 DateFormatter 实例。
所以,您不是这样写的
let formatter = DateFormatter()
formatter.locale = .current
formatter.timeZone = .current
formatter.dateFormat = "HH:mm:ss"
而是这样写
let formatter = DateFormatter.customDateFormatter(format: .fullTime(format: .twentyFour))
您也可以可选地选择区域设置和时区
let formatter = DateFormatter.customDateFormatter(format: DateFormatter.DateFormat, locale: Locale(identifier: "en-US"), timeZone: .gmt)
或使用默认值:
.current
如果您未指定格式,则默认使用 .fullTimeAndDate
格式
let formatter = DateFormatter.customDateFormatter()
可用的格式模板 | 表示 |
---|---|
.time(withOnly: .hours) | 23 |
.time(withOnly: .hoursAndMinutes) | 23:59 |
.time(withOnly: .minutes) | 59 |
.time(withOnly: .minutesAndSeconds) | 59:59 |
.time(withOnly: .seconds) | 59 |
.fullTime(format: .twelve) | 11:59:59 |
.fullTime(format: .twentyFour) | 23:59:59 |
.date(format: .pointNumDate) | 11.08.2023 |
.date(format: .slashNumDate) | 11/08/2023 |
.date(format: .shortWordDate) | 2023 年 8 月 11 日 |
.date(format: .fullWordDate) | 2023 年 8 月 11 日 |
.fullTimeAndDate | 2023 年 8 月 11 日 23:59:59 |
要求
iOS 9+. Swift 3.0。
安装
DateFormatterConstructor 通过 CocoaPods 提供。要安装它,只需将以下行添加到 Podfile 中
pod "DateFormatterConstructor"
DateFormatterConstructor 通过 Carthage 提供。要安装它,只需将以下行添加到 Cartfile 中
github "idapgroup/DateFormatterConstructor"
许可证
TableViewCellRegistrar 在新BSD许可证下可用。有关更多信息,请参阅LICENSE文件。