使用参数startOfDay(for: )
调用Date(timeIntervalSince1970: 0)
时,我得到一个小时的约会
例如:
let twoThousandAndOne = Date(timeIntervalSinceReferenceDate: 0)
let nineteenSeventy = Date(timeIntervalSince1970: 0)
print("Two thousand and one: \(twoThousandAndOne)")
print("Nineteen seventy: \(nineteenSeventy)")
let calendar = Calendar.current
print("Start of two thousand and one: \(calendar.startOfDay(for: twoThousandAndOne))")
print("Start of nineteen seventy: \(calendar.startOfDay(for: nineteenSeventy))")
输出:
Two thousand and one: 2001-01-01 00:00:00 +0000
Nineteen seventy: 1970-01-01 00:00:00 +0000
Start of two thousand and one: 2001-01-01 00:00:00 +0000
Start of nineteen seventy: 1969-12-31 23:00:00 +0000
答案 0 :(得分:1)
您的时区为UTC + 1
v2T{
考虑本地时区,但是o
以UTC显示日期。
要在UTC中打印用vi{
创建的日期,请添加UTC时区
Calendar