Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get current GMT 0 in Swift 3?

Tags:

time

ios

swift

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?

like image 364
Machado Avatar asked Dec 29 '16 16:12

Machado


1 Answers

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

formatter.timeZone = TimeZone(secondsFromGMT:0)

Or this line:

formatter.timeZone = TimeZone(identifier:"GMT")
like image 126
matt Avatar answered Nov 09 '22 05:11

matt