Sunday, February 12, 2012

Create time stamp

[NSDate date] can return the time which refers to GMT.
If you want the appropriate time zone, you need to plus/minus the time different with [NSDate date].
The below code can make up the time for Hong Kong time zone.



- (NSDate *)timeStamp
{
    // Get GMT time
    NSTimeInterval rightNowInterval = [[NSDate date] timeIntervalSince1970];
   
    // time difference is 8 hours between GMT and Hong Kong
    NSTimeInterval estoniaTimeZoneDifference = 60*60*8;//60 seconds, 60 minutes, 8 hours

    // Hong Kong is 8 hours ahead GMT
    NSDate *timeStamp = [NSDate dateWithTimeIntervalSince1970:(rightNowInterval + estoniaTimeZoneDifference)];
    
    return timeStamp;


}

No comments:

Post a Comment