1
NSDateComponentsでNSDateオブジェクトを取得したいが、NSDateの時間はコンポーネントで1時間遅い。NSDateの結果 - (NSDate *)dateFromComponents:(NSDateComponents *)comps
NSCalendar *cal = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
[cal setLocale:[NSLocale currentLocale]];
[cal setTimeZone:[NSTimeZone localTimeZone]];
NSDateComponents *hourComp = [[NSDateComponents alloc] init];
hourComp.timeZone = [NSTimeZone localTimeZone];
[hourComp setHour:18];
NSLog(@"%@",hourComp);
NSLog(@"%@",[cal dateFromComponents:hourComp]);
NSLog(@"%@",[NSDate date]);
コンソール出力:私が欲しいもの
2012-04-10 19:10:57.505 TestDate[9861:f803] <NSDateComponents: 0x6b6ad30>
TimeZone: Europe/Berlin (CEST) offset 7200 (Daylight)
Hour: 18
2012-04-10 19:10:57.507 TestDate[9861:f803] 0001-01-01 17:06:32 +0000
2012-04-10 19:10:57.508 TestDate[9861:f803] 2012-04-10 17:10:57 +0000
は18です:XX:XX