Created
January 11, 2017 08:11
-
-
Save HarrisHan/a71b7584d10adf6478fb8c4749128574 to your computer and use it in GitHub Desktop.
beginningOfDay and endOfDay
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ (NSDate *)beginningOfDay:(NSDate *)date; | |
{ | |
NSCalendar *cal = [NSCalendar currentCalendar]; | |
NSDateComponents *components = [cal components:( NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitYear | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond ) fromDate:date]; | |
[components setHour:0]; | |
[components setMinute:0]; | |
[components setSecond:0]; | |
return [cal dateFromComponents:components]; | |
} | |
+ (NSDate *)endOfDay:(NSDate *)date; | |
{ | |
NSCalendar *cal = [NSCalendar currentCalendar]; | |
NSDateComponents *components = [cal components:( NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitYear | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond ) fromDate:date]; | |
[components setHour:23]; | |
[components setMinute:59]; | |
[components setSecond:59]; | |
return [cal dateFromComponents:components]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment