Question

Je suis très nouveau dans iPhone.J'ai un problème.Tout d'abord, vérifiez mon code.

NSString *timeZone=[NSString stringWithFormat:@"%@",[[NSTimeZone systemTimeZone] abbreviation]];
NSLog(@"Print Time Zone :- '%@'",timeZone);
NSRange Timerange=[timeZone rangeOfString:@"+"];
NSString *time;

if(Timerange.location == NSNotFound)
{
    Timerange=[timeZone rangeOfString:@"-"];
    time=[timeZone substringFromIndex:Timerange.location];
    NSLog(@"Time is :- '%@'",time);
    time=[time stringByReplacingOccurrencesOfString:@"-" withString:@"M"];

}
else
{
    Timerange=[timeZone rangeOfString:@"+"];
    time=[timeZone substringFromIndex:Timerange.location];
    NSLog(@"Time is :- '%@'",time);
    time=[time stringByReplacingOccurrencesOfString:@"+" withString:@"P"];
}

Son fonctionnement approprié dans iPhone Simulator 4.2 Mais il se bloque dans Simulator 4.3, alors que peut-être le problème?

merci

Était-ce utile?

La solution

NSDate *date=[NSDate date]; 
    NSDateFormatter *formatter=[[NSDateFormatter alloc]init]; 
    [formatter setDateFormat:@"MM/dd/yyyy hh:mm:ss a"];
    [formatter setTimeZone:[NSTimeZone systemTimeZone]];

    [formatter setTimeStyle:NSDateFormatterLongStyle]; 

    NSString *dateOfGame =[formatter stringFromDate:date]; 

    NSString *timeZone = [dateOfGame substringFromIndex:12];

    NSLog(@"dateOfGame%@",timeZone);

try with this code

Autres conseils

you might need coded like this

NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"] autorelease]];
[dateFormatter setDateFormat:@"z"];

NSDate *date = [NSDate date];
NSString *dateString = [dateFormatter stringFromDate:date];
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top