문제

I am trying to get an NSDate object from the first day of the current month. I use the following code:

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

    NSDate *dayOneInCurrentMonth = [c dateFromComponents:components];

However when I log this date, it gives me the day before

day one = 2013-09-30 22:00:00 +0000 
도움이 되었습니까?

해결책

You are logging the date in GMT time zone (+0000). Try logging this:

NSLog(@"new date: %@", [dayOneInCurrentMonth descriptionWithLocale:[NSLocale systemLocale]]);

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top