NSDate - GMT on iPhone

Posted by Mick Walker on Stack Overflow See other posts from Stack Overflow or by Mick Walker
Published on 2010-04-05T22:55:39Z Indexed on 2010/04/06 0:13 UTC
Read the original article Hit count: 792

Filed under:
|
|
|

I have the following code in a production application which calculates a GMT date from the date the user enters:

NSDate *localDate = pickedDate;
    NSTimeInterval timeZoneOffset = [[NSTimeZone defaultTimeZone] secondsFromGMT]; // You could also use the systemTimeZone method
    NSTimeInterval gmtTimeInterval = [localDate timeIntervalSinceReferenceDate] - timeZoneOffset;
    NSDate *gmtDate = [NSDate dateWithTimeIntervalSinceReferenceDate:gmtTimeInterval];

The code was working fine, until the dreaded daylight savings time came into force in the UK last week.

How can I convert the date into GMT whilst taking into account daylight savings?

© Stack Overflow or respective owner

Related posts about iphone

Related posts about nsdate