2013-10-20 3 views
0

현재 달의 첫날부터 NSDate 객체를 가져 오려고합니다. 당신은 GMT 시간대의 날짜 (0000)에 로그인하는달의 첫 번째 달 가져 오기

day one = 2013-09-30 22:00:00 +0000 
+2

시간대는 UTC -2입니까? 이 경우 dayOneInCurrentMonth가 정확한 날짜이지만 NSLog가이 표준 시간대 수정 – Jeepston

+0

@ Jeepston과 함께 출력합니다. You and Joel이 옳았습니다. 그것은 시간대입니다. –

답변

3

전에이 날짜를 기록 할 때

NSDateComponents *components = [c components:(NSEraCalendarUnit | NSYearCalendarUnit | NSMonthCalendarUnit | NSWeekdayOrdinalCalendarUnit | NSDayCalendarUnit) fromDate:[NSDate date]]; 
    components.day = 1; 

    NSDate *dayOneInCurrentMonth = [c dateFromComponents:components]; 

그러나, 그것은 나에게 일을 제공 : 다음 코드를 사용합니다. 로깅을 시도해보십시오.

NSLog (@ "새 날짜 : % @", [dayOneInCurrentMonth descriptionWithLocale : [NSLocale systemLocale]]);

관련 문제