Scenes:
Using swift in iOS development
Provide a string and convert it into time format. The converted time is 8 hours less.
let format = DateFormatter.init() format.dateFormat = "yyyy-MM-dd HH:mm:ss" let start = format.date(from: "2023-05-15 16:00:05")! print("start:\(start)")
start:2023-05-15 08:00:05 +0000
solve:
let format = DateFormatter.init()
format.dateFormat = "yyyy-MM-dd HH:mm:ss"
//设置时区为UTC
format.timeZone = TimeZone(identifier: "UTC")
let start = format.date(from: "2023-05-15 16:00:05")!
print("start:\(start)")
Output:
start:2023-05-15 16:00:05 +0000