2015-01-15 3 views
2

이 아닌 명백한 코드의 행동을 제발 도와주세요날짜 형식이 잘못 되었습니까?

NSCalendar *calendar = [NSCalendar currentCalendar]; 

NSDateComponents *dateComponents = [[NSDateComponents alloc] init]; 
dateComponents.hour  = 15; 
dateComponents.minute = 20; 
dateComponents.calendar = calendar; 

NSDate * endDate = [calendar dateFromComponents:dateComponents]; 

종료 날짜 0001-01-01 12시 49분 43초 0000입니다. 왜?

표준 시간대의 차이로 인해 시간 값이 정확하지 않을 수 있습니다. 그런 이상한 분과 초가 왜 가치가 있나? 감사합니다. 때문에

+2

짐작할 수 있겠지만, 이것은 01/01/0001 이후 캘린더에 누적 된 초 단위로 인해 발생한다고 말하고 싶습니다. 그래서 올해를 설정하려고합니다. 하지만이 일이 완전히 잘못되었을 수도 있습니다. –

+0

흥미 롭습니다 ... 달력의 시간대 속성 인 esp의 속성을 인쇄 할 수 있습니까? 'secondsFromGMT'와''abbreviation'. –

+0

@GuillaumeAlgis 좋은 생각! –

답변

1

것은 우리는 단지, 다음 코드

NSCalendar *calendar = [NSCalendar currentCalendar];   
NSDateComponents *components = [[NSDateComponents alloc] init]; 
[components setCalendar:calendar]; 
NSDate *date = [calendar dateFromComponents:components]; 

date = 0000-12-31 23:06:32 +0000을 고려하는 경우 :

캘린더 에서 계산 시간의 시스템에 대한 정보를 캡슐화 이는의 시작, 길이 및 부서 년이 정의됩니다.

는 [...]

완전히 절대 시간을 지정하기 위해 제공 불충분 성분있다

는 캘린더는 선택 디폴트 값을 사용한다. Apple Documentation

NSDateComponents 객체 자체 의미이고; 당신은 그것이 해석되는 달력을 알아야하며, 그 값이 단위의 절대 값인지 또는 단위의 양인지를 알아야합니다. Apple Documentation

실제로 모든 것이 잘되고 설명서에서 말하는 내용입니다.

+1

설명서를 읽었지 만 실제로 어떻게 작동하는지에 의문의 여지가있었습니다. 고마워. –

관련 문제