Created
October 25, 2018 21:59
-
-
Save MihaelIsaev/aac0ae728d34448e98464bf134f912c0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
extension TimeZone { | |
func GMTOffset() -> String { | |
var offsetSeconds = secondsFromGMT() | |
var offsetString = "+00:00" | |
var offsetSymbol = "+" | |
var offsetHoursLeadString = "0" | |
var offsetMinutesLeadString = "0" | |
if offsetSeconds < 0 { | |
offsetSymbol = "-" | |
offsetSeconds = (offsetSeconds * -1) | |
} | |
let offsetHours = Int(offsetSeconds / 3600) | |
let offsetMinutes = offsetSeconds - (offsetHours * 3600) | |
if offsetHours > 10 { | |
offsetHoursLeadString = "" | |
} | |
if offsetMinutes > 10 { | |
offsetMinutesLeadString = "" | |
} | |
offsetString = String(format: "%@%@%i:%@%i", offsetSymbol, offsetHoursLeadString, offsetHours, offsetMinutesLeadString, offsetMinutes) | |
return offsetString | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment