Here's an example function in Swift that converts a given date in Pacific time to GMT:
main.swift550 chars17 lines
This code creates two TimeZone
objects for Pacific time and GMT, respectively. It then creates a DateFormatter
object with the Pacific time zone and a format of "yyyy-MM-dd HH:mm:ss".
The code then converts the input date
to Pacific time using the formatter, retrieves the GMT offset for that time, and creates a new Date
object with the offset applied.
Note that this function may return nil if the input date is formatted incorrectly or cannot be converted to Pacific time. Additionally, since time zones can be affected by daylight saving time, the conversion between Pacific time and GMT may not always be consistent.
gistlibby LogSnag