1

这段代码。

NSDate *today = [NSDate date];  
NSArray *langs = [NSLocale preferredLanguages];
NSString *langID = [langs objectAtIndex:0];
NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:langID];
*format = [[NSDateFormatter alloc] init];
[format setLocale:locale];
[format setDateFormat:@"yyyy/MM/dd HH:mm:ss"];
strTime = [[NSString alloc] initWithFormat:@"%@",[format stringFromDate:today]]; 

today is +0000.    
langID is en.    
but,strTime is Japan time.    

为什么?我想根据语言设置显示日期和时间。

4

1 回答 1

1

代替

NSArray *langs = [NSLocale preferredLanguages];
NSString *langID = [langs objectAtIndex:0];
NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:langID];

试试这个,

NSLocale *locale = [NSLocale currentLocale];

那应该有帮助。

于 2012-12-10T19:16:09.220 回答