Skip to content

Instantly share code, notes, and snippets.

@sag333ar
Created November 15, 2013 10:03
Show Gist options
  • Save sag333ar/7481995 to your computer and use it in GitHub Desktop.
Save sag333ar/7481995 to your computer and use it in GitHub Desktop.
Get current Date mid-night time = 15-Feb-2013 00:00:00 So, You will get date with time 00:00:00 always.
- (NSDate*) currentDate_midnightTime {
NSCalendar *cal = [NSCalendar currentCalendar];
NSDate *now = [NSDate date];
NSDateComponents *comp = [cal components:NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit fromDate:now];
comp.timeZone=[NSTimeZone defaultTimeZone];
comp.month = comp.month;
comp.year = comp.year;
comp.day = comp.day;
[comp setHour:0];
[comp setMinute:0];
[comp setSecond:0];
NSDate *fromDate = [cal dateFromComponents:comp];
return fromDate;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment