【发布时间】:2017-11-22 21:01:43
【问题描述】:
我以这种方式从给定日期获取年、月和日。
let today=Date()
var calendar = Calendar.current
calendar.timeZone = .current
let components = calendar.dateComponents([.year, .month, .day], from: today)
let day=components.day
但是我比现在提前一天。我该如何解决这个问题?
【问题讨论】:
-
试试
TimeZone(abbreviation: "GMT")!换成timeZone -
@Tj3n 但是如果我比格林威治标准时间提前 5.6 小时呢?
-
也许是因为你提前了一天
-
@Tj3n 是的,我想获取与设备时区相关的日期
-
@user1960169
calendar.timeZone = .current正在进行本地时间转换。您当前的时区是?