要在iOS上获取UTC时间,可以使用DateFormatter类来格式化日期和时间。以下是一个示例代码,演示如何获取当前的UTC时间:

let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
dateFormatter.timeZone = TimeZone(abbreviation: "UTC")

let utcDate = dateFormatter.string(from: Date())
print(utcDate)

这段代码将当前日期和时间格式化为yyyy-MM-dd HH:mm:ss的格式,并设置时区为UTC。然后,使用string(from: Date())方法将当前时间转换为UTC时间字符串。

希望这可以帮助到你!

ios 获取utc时间

原文地址: https://www.cveoy.top/t/topic/iRNs 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录