Timezoneoffset error when daylightsaving in effect in iOS

Posted by Ranjit on Stack Overflow See other posts from Stack Overflow or by Ranjit
Published on 2012-03-22T09:30:48Z Indexed on 2012/11/16 23:00 UTC
Read the original article Hit count: 206

Filed under:
|
|

friends,I am getting a date based on the calculation I have done below

      NSCalendar *gregorian          = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];

        NSDate *expectedDate           = [gregorian dateByAddingComponents:components toDate:startDate options:0];
        NSTimeInterval timeZoneOffset  = -[[NSTimeZone systemTimeZone] secondsFromGMTForDate:expectedDate];
        NSDate *localDate              = [expectedDate dateByAddingTimeInterval:(timeZoneOffset)];

         NSString *date  = [dateFormatter stringFromDate:localDate];

But the date goes wrong when the daylightsaving is in effect,and also the timeZoneOffset changes when the daylightsaving is in effect, but I want the same date irrespective of whether the daylight saving is in effect or no..

So friends,how shall I handle this situation,please help.

Regards Ranjit

© Stack Overflow or respective owner

Related posts about ios

Related posts about ios5