Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compare iOS Time Zone Rules

If the user is in Eastern time, I don't want to display "EST" or "EDT" but if they are not, I do want to display it.

Is there an easy way to compare TimeZone rules in iOS?

[NSTimeZone localTimeZone] returns America/Indianapolis, but I just want to know if it is eastern.

Comparing data does not work, do I just compare secondsFromGMT?

EDIT Comparing offsets does seem to work, but I don't know if it is going to cause problems later?

like image 223
dewyze Avatar asked Apr 01 '26 17:04

dewyze


1 Answers

You can use [[NSTimeZone localTimeZone] abbreviation]; to get the abbreviation of whatever time zone the user is in.

This gives the abbreviation of the current date (EDT if not daylight savings and EST if daylight savings, in your case). If you want the abbreviation of a specific date, you can use abbreviationForDate: and insert any date.

Here is some more information about NSTimeZone

Edit:

If you want to actually compare multiple time zones (as in to check if it is the current time zone or not), you can use isEqualToTimeZone:. If that does not fit your needs, look at some of the other NSTimeZone methods in that link.

like image 105
Jsdodgers Avatar answered Apr 03 '26 06:04

Jsdodgers