Friday, May 3, 2013

NSTimeZone daylightSavingTimeOffset example ios


daylightSavingTimeOffset

Returns the current daylight saving time offset of the receiver.
- (NSTimeInterval)daylightSavingTimeOffset
Return Value
The daylight current saving time offset of the receiver.
Example of [NSTimeZone daylightSavingTimeOffset]
NSTimeZone *systemTimeZone = [NSTimeZone systemTimeZone];
NSLog(@"%lf", [systemTimeZone daylightSavingTimeOffset]); //This works
[systemTimeZone release]; //Testing release do not actually do this

systemTimeZone = [NSTimeZone systemTimeZone];
NSLog(@"%lf", [systemTimeZone daylightSavingTimeOffset]); //This works
[systemTimeZone release]; //Testing release do not actually do this

systemTimeZone = [NSTimeZone systemTimeZone];
NSLog(@"%lf", [systemTimeZone daylightSavingTimeOffset]); //This crashes EXC_BAD_ACCESS
//The cached systemTimeZone at this point has been over released.
Example of [NSTimeZone daylightSavingTimeOffset]
int  gmtOffset =  [[NSTimeZone localTimeZone] secondsFromGMT];
 int daylightOffset =  [[NSTimeZone localTimeZone] daylightSavingTimeOffset];

  int daySeconds =  ((int)([date timeIntervalSinceReferenceDate]+gmtOffset+daylightOffset))%(86400+1);

 NSLog(@"Day seconds: %i", daySeconds);