To convert GMT to Eastern Time in Swift, you can use the DateFormatter
and TimeZone
classes. Here's an example code snippet:
main.swift518 chars10 lines
In the code above, we first create a DateFormatter
object and set the date format to match the format of the input string. Then, we set the timezone of the formatter to GMT and create a Date
object from the input string.
Next, we set the timezone of the formatter to Eastern Time (EST) and use the formatter to convert the Date
object to a string in Eastern Time. Finally, we print the resulting string to the console.
Note that the timezone abbreviations used here (GMT
and EST
) are just examples and you should use the correct abbreviations for your specific timezone.
gistlibby LogSnag