nsdatecomponent

How to set time on NSDate?

丶灬走出姿态 提交于 2019-12-18 13:17:43
问题 I want to set the NSDate time with my desired hours:minutes:seconds currently im working with NSDate component but it is not giving the desired result [comps setHour: -hours]; [comps setMinute:0]; [comps setSecond:0]; NSDate *minDate = [calendar_c dateFromComponents:comps]; 回答1: Your approach should work fine. I needed a solution for this type problem (setting the individual date components) and the following code works as expected for me. My situation: I wanted to create a date object that

NSDateComponents - day method returning wrong day

浪尽此生 提交于 2019-11-28 21:35:26
I can't seem to figure out why the day doesn't change when I get to the 6th of November, 2011. All I'm doing is iterating through the days. Any help would be appreciated. Here is my code: NSCalendar* calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSDateComponents* comp = [[NSDateComponents alloc] init]; [comp setDay:2]; [comp setMonth:11]; [comp setYear:2011]; NSDate* date = [calendar dateFromComponents:comp]; for (int i = 0; i < 7; i++) { NSDate* d = [date dateByAddingTimeInterval:((3600 * 24) * i)]; NSDateComponents* dComponents = [calendar components:

NSDateComponents - day method returning wrong day

流过昼夜 提交于 2019-11-27 14:11:54
问题 I can't seem to figure out why the day doesn't change when I get to the 6th of November, 2011. All I'm doing is iterating through the days. Any help would be appreciated. Here is my code: NSCalendar* calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSDateComponents* comp = [[NSDateComponents alloc] init]; [comp setDay:2]; [comp setMonth:11]; [comp setYear:2011]; NSDate* date = [calendar dateFromComponents:comp]; for (int i = 0; i < 7; i++) { NSDate* d = [date