Skip to content

Instantly share code, notes, and snippets.

@Krizzzn
Created September 4, 2011 11:02
Show Gist options
  • Save Krizzzn/1192669 to your computer and use it in GitHub Desktop.
Save Krizzzn/1192669 to your computer and use it in GitHub Desktop.
Objective-C: Dateformatter
- (NSString *)format: (NSDate*) date usingFormat:(NSString *)dateFormat
{
NSCalendar *cal = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:dateFormat];
[formatter setCalendar:cal];
[formatter setLocale:[NSLocale currentLocale]];
NSString *ret = [formatter stringFromDate:date];
[formatter release];
[cal release];
return ret;
}
// USAGE:
// [self format: theDateToFormat usingFormat:@"H:mm"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment