Non ottenere il fuso orario appropriato
-
14-11-2019 - |
Domanda
Sono molto nuovo in iPhone.Ho un problema.Prima basta controllare il mio codice.
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"];
}
.
Il suo funzionamento corretto in iPhone Simulator 4.2 ma si blocca nel simulatore 4.3 Quindi quale può essere il problema?
Grazie
Soluzione
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
Altri suggerimenti
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];
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow