Created
January 15, 2010 08:30
-
-
Save alexrinass/277903 to your computer and use it in GitHub Desktop.
Create date from today, without time in Cocoa
This file contains 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
@interface NSDate (Today) | |
// Create date from today, without time | |
+ (NSDate *)dateWithToday; | |
@end |
This file contains 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
#import "NSDateToday.h" | |
@implementation NSDate (Today) | |
+ (NSDate *)dateWithToday { | |
NSCalendar *calendar = [NSCalendar currentCalendar]; | |
unsigned unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit; | |
NSDateComponents *dateComponents = [calendar components:unitFlags fromDate:[NSDate date]]; | |
return [calendar dateFromComponents:dateComponents]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment