Set a specific time zone worldwide to use the application.

I am writing an application that should display and calculate all dates, times, time intervals, etc. from a specific, given time zone in Europe. The point is, if I, say, in Paris, the application works flawlessly, but if I go to New York, the application should display and work just like if I were still in Paris.

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

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

but of course this does not work, all of my NSDateFormatter objects still use the current time zone, unless explicitly stated otherwise.

So, I would like to know:

  • Is there a way to globally enforce timezone in an application? I would prefer not to go through all my code and not fix every date formatter and date picker, etc., if there is another way.

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

Thanks in advance!

+4
source share
1 answer
+12
source

Source: https://habr.com/ru/post/1397632/


All Articles