To convert a date from GMT to Australian Western Time in Swift, you need to use the TimeZone
and DateFormatter
classes. Here's how you can do it:
main.swift500 chars16 lines
In this example, we first create a DateFormatter
object and set its format to match our input string. We then set the time zone of the formatter to GMT and convert our input string to a date object.
Next, we set the time zone of the formatter to Australian Western Time ("Australia/Perth"
) and use it to format our date object. Finally, we print the output string to verify the conversion.
gistlibby LogSnag