To convert Chatham time to GMT in Swift, you need to use the DateFormatter
and TimeZone
classes.
First, you need to create two TimeZone
objects, one for Chatham Time and the other for GMT.
main.swift110 chars3 lines
Next, create an instance of DateFormatter
and set the time zone to Chatham Time.
main.swift126 chars4 lines
Now you can convert a Chatham Time String
to Date
:
main.swift109 chars3 lines
Finally, set the time zone of the Date
object to GMT and format it as a String
.
main.swift149 chars4 lines
The resulting String
will be the equivalent time in GMT.
gistlibby LogSnag