您可以使用以下代码获取完整的标准本地化时区名称
目标 c:
NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Pacific/Auckland"];
NSString* timeZoneName = [timeZone localizedName:NSTimeZoneNameStyleStandard
locale:[NSLocale currentLocale]];
NSLog(@"%@", timeZoneName);
斯威夫特:
let timezone:TimeZone = TimeZone.init(identifier: "Pacific/Auckland") ?? TimeZone.current
print(timezone.localizedName(for: .generic, locale: .autoupdatingCurrent))
print(timezone.localizedName(for: .standard, locale: .autoupdatingCurrent))
输出:
目标 c:
新西兰标准时间
斯威夫特:
可选(“新西兰标准时间”)
可选(“新西兰标准时间”)
我认为现在您可以通过拆分和组合字符串从新西兰标准时间获得NZST
目标 c:
NSMutableString * firstCharacters = [NSMutableString string];
NSArray *wordsArray = [timeZoneName componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
for (NSString * word in wordsArray){
if ([word length] > 0){
NSString * firstLetter = [word substringToIndex:1];
[firstCharacters appendString:[firstLetter uppercaseString]];
}
}
NSLog(@"%@", firstCharacters);
斯威夫特:
let fullName = timezone.localizedName(for: .standard, locale: .autoupdatingCurrent) ?? ""
var result = ""
fullName.enumerateSubstrings(in: fullName.startIndex..<fullName.endIndex, options: .byWords) { (substring, _, _, _) in
if let substring = substring { result += substring.prefix(1) }
}
print(result)
输出:
新西兰标准时间