0
我想從本月的第一天獲取NSDate對象。我使用下面的代碼:獲取月的第一天
NSDateComponents *components = [c components:(NSEraCalendarUnit | NSYearCalendarUnit | NSMonthCalendarUnit | NSWeekdayOrdinalCalendarUnit | NSDayCalendarUnit) fromDate:[NSDate date]];
components.day = 1;
NSDate *dayOneInCurrentMonth = [c dateFromComponents:components];
然而,當我登錄這個日期,它給了我前一天
day one = 2013-09-30 22:00:00 +0000
是您的時區UTC -2?在這種情況下,dayOneInCurrentMonth是正確的日期,但NSLog輸出它與此時區更正 – Jeepston
@Jeepston你和喬爾是正確的。這是時區。 –