関数の引数として渡された任意の時刻文字列に対応するUTC時刻文字列を取得する関数を記述しました。夏時間の取得と夏時間の処理
+(NSString *)getUTCTime:(NSString *)selectedTime
{
NSString *strFormat;
if ([self is24HourFormat:selectedTime]){
strFormat = @"HH:mm";
}
else{
strFormat = @"hh:mm a";
}
NSLocale *baseLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
NSDateFormatter *dateFormatterlocal = [[NSDateFormatter alloc] init];
[dateFormatterlocal setTimeZone:[NSTimeZone systemTimeZone]];
dateFormatterlocal.locale = baseLocale;
[dateFormatterlocal setDateFormat:strFormat];
NSDate *selectedDate = [dateFormatterlocal dateFromString:selectedTime];
NSDateFormatter *dateFormatterUTC = [[NSDateFormatter alloc] init];
[dateFormatterUTC setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]];
dateFormatterUTC.locale = baseLocale;
[dateFormatterUTC setDateFormat:strFormat];
NSString *utcTimeString = [dateFormatterUTC stringFromDate:selectedDate];
return utcTimeString;
}
インドのタイムゾーンムンバイでは問題ありません。しかし、私がロンドンにタイムゾーンを変更すると、私は関数の引数を渡しているのと同じ時間を返します。現在、ロンドンではUTC + 1です。 NSDateFormatter
は夏時間を処理しますか?夏時間のために、以下に示すよう
正確に何が必要ですか?あなたはutc形式で時間が欲しいですか? – Lion
ユーザーが選択した時間に対応するUTC時間をサーバーに送信する必要があります。 –
定義上、UTCにはタイムゾーンがありません。あなたはGMT + 1を意味すると思います。 – Avi