Pergunta

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!

Foi útil?

Solução

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

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top