ios - 如何在 Swift 3 中获取当前的 GMT 0?

标签 ios swift time

我正在寻找一种显示当前 GMT-0 时间的方法。

到目前为止,我一直在这样做:

    let UTCDate = Date()
    let formatter = DateFormatter()
    formatter.dateFormat = "yyyy-MM-dd HH:mm:ss"

    let defaultTimeZoneStr = formatter.string(from: UTCDate)

但是它返回手机的当前时间。

如何使用 Swift 3 获取当前的 GMT-0 时间?

最佳答案

在代码的最后一行之前,插入这一行:

formatter.timeZone = TimeZone(secondsFromGMT:0)

或者这一行:

formatter.timeZone = TimeZone(identifier:"GMT")

关于ios - 如何在 Swift 3 中获取当前的 GMT 0?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41383409/

相关文章:

ruby-on-rails - rails : How to properly set up the timezone on the production server (EC2 Ubuntu)?

java - DateFormat 返回错误的小时

ios - (iOS 错误?)NSURLRequest 缓存的授权通过不正确的凭据

ios - 需要 UIButton 图像不透明度

swift - 如何同时控制两个UITextField的数据?

ios - 游戏运行一段时间后 AVAudioPlayer 返回 nil

ios - Objective-C - 类似于 CLLocationCoordinate2DMake 的自定义结构 'make' 方法

ios - 找不到 Apple 开发推送服务的私钥

ios -/ml 模型/Inception V3.ml 模型 : unable to read document

java - 定时java循环