날짜가 정수 속성 day of the year
및 year
(실제 "천재"디자인 ...)에 저장되는 기존 데이터 객체에 대한 GUI를 작성하고 있습니다.Objective-C : 주어진 날짜와 연말 연시
어떻게하면이 데이터를 해당 연도의 요일과 월로 변환 할 수 있습니까?
나는 현재 노력하고있어 :
int theYear = 2016;
int theDayOfTheYear = 222;
NSCalendar* gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *components = [[NSDateComponents alloc] init];
[components setYear:theYear];
[components setDay:theDayOfTheYear];
NSDate* theDate = [gregorian dateFromComponents:components];
이 나에게 조금 너무 해키 보인다. NSDateComponents 클래스 참조에서이 문제에 대한 언급을 찾지 못한 31 일이 넘는 날에도 작동한다는 것은 우연한 일일 수 있습니다. > 가까운,하지만 2016-08-09
해야
즉 일반 DD-MM-YYYY 날짜를 변환, 역 작업을 수행하려면 -
내가 디버깅, po theDate
나에게 2016-08-08 22:00:00 +0000
을 제공합니다 (!) day of the year
에,이 코드를 사용하고 있습니다 ...
NSDate *fullDate = [NSDate date];
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSUInteger dayOfYear = [gregorian ordinalityOfUnit:NSDayCalendarUnit
inUnit:NSYearCalendarUnit
forDate:fullDate];
을하지만 반대 할 적절한 방법을 찾을 수 없습니다
; 하루 구성 요소는 달력에 따라 해석됩니다 (정확하게 작동하는 방식이 불분명 함). 또한 출력 날짜를 디버깅하는 WRT; 'po'가 현지 시간대가 아닌 UTC로 날짜/시간을 인쇄 할 것이라고 생각 했습니까? – Droppy