0

I need to calculate time difference between current device located time zone time and system time(iphone and ipad)if the user time changes manually current device date or time. If it set automatic i am able to get but if user changes manually date or time i facing problem.

venkipar
  • 141
  • 1
  • 2
  • 7
  • Current device located time & System time (iPhone and iPad). Don't you think these are both same? – Kampai Dec 10 '14 at 05:58
  • Ya its same.. there only my problem came, Actually i am calculating time difference for delta value to reach server. If its automatic i am getting exact time zone. but after changing the timezone user changes time his manually some hours before or after.. then on that time i need to find timezone to time how many hours difference – venkipar Dec 10 '14 at 06:27

2 Answers2

1

The app or user may change either the default time zone for an application (using +[NSTimeZone setDefaultTimeZone]) or the system time zone (using System Preferences) at any time. +[NSTimeZone localTimeZone] returns a proxy that will always act as if it is the current default time zone for the application, even if that default changes. You could change the default time zone for an application to make it behave as if it were in a different time zone.

+[NSTimeZone systemTimeZone] returns the current system time zone (as set using System Preferences). In most cases, these will be the same (the app's default time zone is set to the system time zone at app startup, I believe).

If you want to know the system's time zone setting, you probably want to use +[NSTimeZone systemTimeZone]. If you just want the correct time zone for your app to work in, you probably want +[NSTimeZone localTimeZone].

refere to the link: NSTimeZone

Community
  • 1
  • 1
Satish Azad
  • 2,302
  • 1
  • 16
  • 35
0

You have to take care when user change time zone or time.

There is one delegate method in UIApplication.h class.

- (void)applicationSignificantTimeChange:(UIApplication *)application;        // midnight, carrier time update, daylight savings time change

Override this method in AppDelegate.m. It will call whenever use change device time zone.

So you can store previous time in NSUserDefaults and then in this method measure time difference with new time.

Also there is one notification observer UIApplicationSignificantTimeChangeNotification. Add this observer to your view controller.

For Example:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(timeChanged:) name:UIApplicationSignificantTimeChangeNotification object:nil];

- (void)timeChanged:(NSNotification *)notification {
}
Kampai
  • 22,848
  • 21
  • 95
  • 95