user1858238
user1858238

Reputation:

NSDate About the date and time display

This code.

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.    

Why? I want to show date and time according to the language settings.

Upvotes: 1

Views: 152

Answers (1)

iDev
iDev

Reputation: 23278

Instead of

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

Try this,

NSLocale *locale = [NSLocale currentLocale];

That should help.

Upvotes: 1

Related Questions