2011-08-17 5 views
0

Je suis en train de faire le développement d'un objectif-c (iOS). Puis-je savoir comment je vais changer le fuseau horaire par défaut de GMT +0 à GMT +8. GMT +8 est pour Singapour.Changement de fuseau horaire

Voici mon code:

- (IBAction)dateChanged { 
    NSDate *choice = [datePick date]; 
    NSString *words = [NSString alloc initWithFormat:@"%@", choice]; 
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; 
    [dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; 

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"You have selected:" message:words delegate:nil cancelButoonTitle:@"OK" otherBUttonTitles:nil, nil]; 
    [alert show]; 
    [alert release]; 

    [words release]; 
} 

Merci.

Répondre

1

Vous pouvez utiliser,

NSCalendar *calendar = [NSCalendar currentCalendar]; 
    [calendar setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]]; 

OU,

+ (id)timeZoneForSecondsFromGMT:(NSInteger)seconds 

qui sera dans votre cas,

[calendar setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:8*60*60]];