Created
August 29, 2012 14:25
-
-
Save eternalstorms/3513336 to your computer and use it in GitHub Desktop.
return a well-formatted string from an NSDate, presentable to the user
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 *)stringForDate:(NSDate *)date | |
withLocale:(NSLocale *)locale | |
timeZone:(NSTimeZone *)timeZone | |
dateFormat:(NSString *)dateFormat | |
dateStyle:(NSDateFormatterStyle)style | |
{ | |
if (dateFormat == nil) | |
dateFormat = @"yyyy-MM-dd HH:mm:ss Z"; | |
if (locale == nil) | |
locale = [NSLocale currentLocale]; | |
if (timeZone == nil) | |
timeZone = [NSTimeZone systemTimeZone]; | |
NSDateFormatter *fm = [[NSDateFormatter alloc] init]; | |
fm.locale = locale; | |
fm.timeZone = timeZone; | |
fm.dateFormat = dateFormat; | |
fm.dateStyle = style; | |
fm.timeStyle = style; | |
NSString *str = [fm stringFromDate:date]; | |
[fm release]; | |
return str; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment