世界の専門家の皆様、こんにちは。
私は非常に奇妙な問題に遭遇しました:
次の方法で、00-23 (Google サービスによって返される) の時間を表す文字列をフォーマットしています。
(たとえば 14 という文字列を渡すと、14:00 または 2:00 PM のいずれかが出力されます。ユーザーのローカルによって異なります)
+(NSString *) formatTime: (NSString *)timeToBeFormatted {
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"HH"];
NSDate *date = [[NSDate alloc] init];
date = [dateFormat dateFromString:timeToBeFormatted];
// Convert date object to desired output format
[dateFormat setTimeStyle:NSDateFormatterShortStyle];
timeToBeFormatted = [dateFormat stringFromDate:date];
return timeToBeFormatted;
}
世界中のすべてのローカルですべてが正常に機能します。
ただし、デフォルトが 24 時間であるローカルでユーザーが 12 時間に TIME フォーマットを設定している場合にのみ、フォーマッタは 12 ~ 23 の間の値に対してのみ NULL を返します。
例: before formatter 12 after 12:00 AM before formatter 13 after (null)
なぜこれが起こるのでしょうか?
ありがとう!