【发布时间】:2021-11-17 05:30:33
【问题描述】:
我将日期时间(2021-10-15 18:30:00 UTC,2021-10-15 18:30:00 +0000) 转换为datetime 组件,但缺少小时、分钟和秒
let changedDate = Calendar.current.date(byAdding: .day, value: -10, to: actualDate)!
var datcomp = Calendar.current.dateComponents([.year, .month, .day,.hour,.minute,.second], from: changedDate)
datcomp.timeZone = TimeZone(abbreviation: "GMT")
▿ 2021-10-15 18:30:00 +0000
- timeIntervalSinceReferenceDate : 656015400.0
▿时区:GMT(固定)年:2021月:10日:11时:0分:0 second: 0 isLeapMonth: false ▿ timeZone : GMT (fixed) - 标识符:“GMT” - 种类:“固定” ▿ 缩写:可选 - 一些:“格林威治标准时间” - 秒从格林威治标准时间:0 - isDaylightSavingTime : 假
- 年份:2021
- 月:10
- 天:11
- 小时:0
- 分钟:0
- 秒:0
- isLeapMonth:假
更多日志
实际日期:2021-09-26 18:30:00 +0000 更改日期:2021-09-21 18:30:00 +0000 日期计算:年:2021 月:9 日:22 小时:0 分钟:0 秒:0 isLeapMonth:false
【问题讨论】:
-
什么是
actualDate?它是如何创建/设置的? -
它来自 API
-
当我看到 variable 的值时,它显示为 2021-10-15 18:30:00 UTC
-
当我打印对象时,它显示为 2021-10-15 18:30:00 +0000
-
我建议不要使用 DateComponents 来打印日期。只需
Print(date)。
标签: ios datetime nsdatecomponents gmt