我正在尝试从当月的第一天获取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
答案 0 :(得分:3)
您正在以GMT时区(+0000)记录日期。尝试记录下来:
NSLog(@“new date:%@”,[dayOneInCurrentMonth descriptionWithLocale:[NSLocale systemLocale]]);