NSDate - GMT on iPhone
- by Mick Walker
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?