Created
September 4, 2011 11:02
-
-
Save Krizzzn/1192669 to your computer and use it in GitHub Desktop.
Objective-C: Dateformatter
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
- (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