例如,我需要从 NSDate 中删除时间组件:我的值为 '2012-08-12 22:15:54 +00000' 但我得到的值为 '2012-08-12 03:00:00 +00000'
我正在使用的代码是:
NSDate* getNDateOfWeek(int week, int day) {
NSDate *now = [NSDate date];
NSCalendar *calendar = [[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar] autorelease];
calendar.timeZone = [NSTimeZone systemTimeZone];
unsigned unitFlags = NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit;
NSDateComponents *comp = [calendar components:unitFlags fromDate:now];
[comp setWeekday:day];
[comp setWeek: week];
[comp setHour:0];
NSDate *resultDate = [calendar dateFromComponents:comp];
return resultDate;
}
有什么帮助吗?