iOS NSDate本地化

 

1.

NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
    [outputFormatter setLocale:[NSLocale currentLocale]];
    [outputFormatter setDateFormat:@"yyyy/MM/dd HH:mm:ss"];
NSLog(@"%@",[outputFormatter stringFromDate:[NSDate date]);

 

 

2.

NSString *deviceLanguage = [[NSLocale preferredLanguages] objectAtIndex:0];
    NSDateFormatter *dateFormatter = [NSDateFormatter new];
    NSLocale *locale = [[NSLocale alloc]initWithLocaleIdentifier:deviceLanguage];
    
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss EEEE dd MMMM"];
    [dateFormatter setLocale:locale];
    
    NSLog(@"\nLocal Time = %@",[dateFormatter stringFromDate:[NSDate date]]);

 

posted @ 2016-04-12 15:56  Ficow  阅读(495)  评论(0编辑  收藏  举报