Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set specific timezone globally for app to use

I'm writing an app that needs to display and calculate all dates, times, timeintervals etc. from a specific, given timezone in Europe. Meaning, if I'm, say, in Paris, the app works flawlessly now, but if I go to New York, the app should display and work exactly as if I were still in Paris.

Naively, I tried (in the application: didFinishLaunchingWithOptions: function)

[[NSCalendar currentCalendar] setTimeZone:[NSTimeZone timeZoneWithName:@"Europe/Paris"]];

but of course that doesn't work, all my NSDateFormatter objects still use the current timezone if not explicitly told otherwise.

So, what I'd like to know is:

  • Is there any way to globally enforce a timezone in an app? I'd rather not go through all my code and fix every single date formatter and date picker and so on if there's another way.

  • Will [NSTimeZone timeZoneWithName:@"Europe/Paris"] properly switch between CET and CEST?

Thanks ahead!

like image 878
JiaYow Avatar asked Feb 21 '12 15:02

JiaYow


1 Answers

You can use the method + (void)setDefaultTimeZone:(NSTimeZone *)aTimeZone of the class NSTimeZone.

like image 138
sch Avatar answered Oct 16 '22 23:10

sch