2011-04-07 3 views
1

NSDateComponent를 사용하여 날짜 (즉, 생일)를 지정하려고하면 내가 돌아 오는 날짜가 1 시간 짧다는 것을 알았습니다.NSDateComponent의 NSDate가 1 시간 짧습니까?

NSDateComponents *birthdayComponents = [[NSDateComponents alloc] init]; 
[birthdayComponents setDay:5]; 
[birthdayComponents setMonth:3]; 
[birthdayComponents setYear:1968]; 

NSDate *birthday = [[NSCalendar currentCalendar] dateFromComponents:birthdayComponents]; 
NSLog(@"BIRTHDAY: %@", birthday); 
[birthdayComponents release]; 

.

OUTPUT: "BIRTHDAY: 1968-03-04 23:00:00 +0000" 

나는 추가하여이 문제를 해결할 수 있습니다 이유는 단지 5, 3, 설정 1968는 포기하지 않았다

[birthdayComponents setHour:1]; 

하지만 호기심 1968년 3월 5일 0시 0분 0초 0000?

답변

2

birthdayComponents의 timeZone 속성을 설정하지 않았으므로 기본값은 UTC가됩니다. 날짜를 만들면 날짜 구성 요소가 현지 시간대로 변환됩니다.

1

현재 시간대는 무엇입니까? ;)

날짜를 기록 할 때 GMT로 시간이 표시됩니다. GMT로부터 한시간 떨어져있는 표준 시간대로 시간을 표시하고있을 것입니다.

0

일광 절약 시간으로 인해 비슷한 문제가 발생했습니다. 0400과 0500 등이 발생했습니다. 저는이를 해결하기 위해 시간대와 로케일을 설정했습니다.

// set the locale (for date calculations) 
NSLocale *locale = [[[NSLocale alloc] initWithLocaleIdentifier:@"es_US"] autorelease]; 
endDate.locale = locale; 
관련 문제