NSDateFormatter *stringFormatter = [[NSDateFormatter alloc] init];
NSLocale *locale = [NSLocale currentLocale];
NSLocale *ja;
if ([[locale localeIdentifier] rangeOfString:@"ja_JP"].location == NSNotFound) {
ja = [[NSLocale alloc] initWithLocaleIdentifier:@"ja_JP"];
[stringFormatter setLocale:ja];
}else{
ja = [NSLocale currentLocale];
}
[stringFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"Asia/Tokyo"]];
[stringFormatter setDateFormat:@"yyyyMMddHHmmss"];
有时它返回如下结果:20190211午后。我想保留日本的语言环境,但结果删除了午后。结果应该是:20190211152022。
答案 0 :(得分:0)
尝试一下
NSDateFormatter *stringFormatter = [[NSDateFormatter alloc] init];
NSLocale *locale = [NSLocale currentLocale];
NSLocale *ja;
if ([[locale localeIdentifier] rangeOfString:@"ja_JP"].location == NSNotFound) {
ja = [[NSLocale alloc] initWithLocaleIdentifier:@"ja_JP"];
[stringFormatter setLocale:ja];
}else{
ja = [NSLocale currentLocale];
}
[stringFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"Asia/Tokyo"]];
[stringFormatter setDateFormat:@"yyyyMMddHHmmss"];
NSString * strdate = [stringFormatter stringFromDate:[NSDate date]];
NSLog(@"%@", strdate);
它会变成这样
20181213195829
希望有帮助