Skip to content

Instantly share code, notes, and snippets.

@zachwaugh
Created April 19, 2012 15:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zachwaugh/2421586 to your computer and use it in GitHub Desktop.
Save zachwaugh/2421586 to your computer and use it in GitHub Desktop.
// static var to store shared date formatter
static NSDateFormatter *_formatter = nil;
@implementation NSDate (Extras)
// Simple comparison, create a string from today and date, see if they're the same
- (BOOL)isToday
{
// Lazy load and cache formatter, date formatters are slow to init
if (!_formatter)
{
_formatter = [[NSDateFormatter alloc] init];
[_formatter setTimeStyle:NSDateFormatterNoStyle];
[_formatter setDateStyle:NSDateFormatterShortStyle];
}
// Do stuff with formatter...
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment