9

I'm looking for a way to display the current GMT-0 time.

So far, I've been doing it like:

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

    let defaultTimeZoneStr = formatter.string(from: UTCDate)

However it returns the current time of the phone.

How can I get the current GMT-0 time using Swift 3?

rmaddy
  • 307,833
  • 40
  • 508
  • 550
Machado
  • 13,515
  • 13
  • 49
  • 93

1 Answers1

24

Before the last line of your code, insert this line:

formatter.timeZone = TimeZone(secondsFromGMT:0)

Or this line:

formatter.timeZone = TimeZone(identifier:"GMT")
matt
  • 485,702
  • 82
  • 818
  • 1,064