Pregunta

Soy muy nuevo en iPhone.Tengo un problema.Primero solo revisa mi código.

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"];
}

está funcionando correctamente en el simulador de iPhone 4.2 Pero se bloquea en el simulador 4.3 Entonces, ¿cuál puede ser el problema?

gracias

¿Fue útil?

Solución

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

Otros consejos

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];
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top