ユーザーのタイムゾーンとロンドンの GMT 時間との差の情報を時間または分単位で取得する必要があります。
誰でも助けることができますか?
色々と調べていて、迷っています。
ありがとう、
ルイ
ユーザーのタイムゾーンとロンドンの GMT 時間との差の情報を時間または分単位で取得する必要があります。
誰でも助けることができますか?
色々と調べていて、迷っています。
ありがとう、
ルイ
NSTimeZone には というメソッドがありsecondsFromGMT
ます。
戻り値
受信者とグリニッジ標準時の現在の差 (秒単位)。
これがお役に立てば幸いです:
NSInteger hours, min;
NSDateFormatter *dateFormatterGMT = [[NSDateFormatter alloc] init];
//GMT Time Zone
NSTimeZone *gmt = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
[dateFormatterGMT setTimeZone:gmt];
dateFormatterGMT.dateFormat = @"h";
hours = [[dateFormatterGMT stringFromDate:[NSDate date]] intValue];
NSLog(@"%ld", hours);
dateFormatterGMT.dateFormat = @"mm";
min = [[dateFormatterGMT stringFromDate:[NSDate date]] intValue];
NSLog(@"%ld", min);
//User Time Zone
NSDateFormatter *dateFormatterUser = [[NSDateFormatter alloc] init];
NSDate *userDate = [NSDate date];
dateFormatterUser.dateFormat = @"h";
hours = [[dateFormatterUser stringFromDate:userDate] intValue];
NSLog(@"%ld", hours);
dateFormatterUser.dateFormat = @"mm";
min = [[dateFormatterUser stringFromDate:userDate] intValue];
NSLog(@"%ld", min);
[dateFormatterUser release];