Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GMT time on iPhone

Tags:

iphone

nsdate

How do I get GMT time?

NSDate *c =[NSDate date];

gives system time, not GMT.

like image 461
g.revolution Avatar asked Sep 29 '09 04:09

g.revolution


1 Answers

This is a simpler version of Ramin's answer

+ (NSDate *) GMTNow
{ 
 NSDate *sourceDate = [NSDate date];
    NSTimeZone* currentTimeZone = [NSTimeZone localTimeZone];
    NSInteger currentGMTOffset = [currentTimeZone secondsFromGMT];

    [sourceDate addTimeInterval:currentGMTOffset];

    return sourceDate;
}
like image 71
Chris Avatar answered Sep 18 '22 21:09

Chris