NSDate is always represented in GMT. It's just how you represent it that may change.
If you want to print the date to label.text
, then convert it to a string using NSDateFormatter
and [NSTimeZone localTimeZone]
, as follows:
NSString *gmtDateString = @"08/12/2013 21:01";
NSDateFormatter *df = [NSDateFormatter new];
[df setDateFormat:@"dd/MM/yyyy HH:mm"];
//Create the date assuming the given string is in GMT
df.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0];
NSDate *date = [df dateFromString:gmtDateString];
//Create a date string in the local timezone
df.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:[NSTimeZone localTimeZone].secondsFromGMT];
NSString *localDateString = [df stringFromDate:date];
NSLog(@"date = %@", localDateString);
// My local timezone is: Europe/London (GMT+01:00) offset 3600 (Daylight)
// prints out: date = 08/12/2013 22:01
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…