Create NSDate today at a specific hour and minute

How can I create NSDatewith today's date and hour, minutes and seconds 5, 0 and 0 respectively? That is, the date will be 07/02/2010 05:00:00

+3
source share
1 answer
//Gives us the current date
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *components = [gregorian components:NSYearCalendarUnit | NSMonthCalendarUnit |  NSDayCalendarUnit fromDate:[NSDate date]];
[components setHour:5];
NSDate * date = [gregorian dateFromComponents:components];
[gregorian release];

Something along these lines should do the trick.

+7
source

Source: https://habr.com/ru/post/1752759/


All Articles