To convert a date from GMT to New Zealand time in Swift, you can use the following code:
main.swift453 chars13 linesIn this code, we first create a Date object representing the current date in GMT. We then create a date formatter and set its time zone to GMT. We use this formatter to convert the gmtDate object to a string with the format yyyy-MM-dd HH:mm:ss.
Next, we change the time zone of the formatter to New Zealand (Pacific/Auckland), and use it to convert the string to a new string representing the same date and time in New Zealand time.
Finally, we pass the resulting string back to the formatter to convert it to a Date object, which we store in the nzDate variable.
gistlibby LogSnag