Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift iOS TimeZone as String?

How do I get a String, "Pacific/Auckland" for example, from a user's TimeZone?

I can get the "NZST" abbreviation with

TimeZone.current.abbreviation()

But it's the full name I need, if I can get it.

like image 830
HenryRootTwo Avatar asked Jul 27 '26 06:07

HenryRootTwo


1 Answers

One of these should work for you.

timeZone = TimeZone(abbreviation: "EST")
print(timeZone) // "some(America/New_York (current))\n"
print(timeZone.abbreviation()) // "Optional("EDT")\n"
print(timeZone.description) // "America/New_York (current)\n"
print(timeZone.identifier) // "America/New_York\n"

I believe you are looking for the last one.

like image 194
Daniel Lyon Avatar answered Jul 29 '26 20:07

Daniel Lyon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!