Apr 06

Formatting a proper date string can be a bit tedious, I’ve tried to work with the time function available in C, but that didn’t work out very well due dates not getting converted properly to my locale (Dutch in my case).

After fiddeling quite a bit, it turned out that combining NSDateFormatter with NSLocale and NSDate would work the magic I needed for displaying a proper date in a UITableView.

NSDateFormatter *setDateLocale = [[NSDateFormatter alloc] init];
NSLocale *nl_NL = [[NSLocale alloc] initWithLocaleIdentifier:@"nl_NL"];
[setDateLocale setDateFormat:@"EEE, d MMM yyy"];
[setDateLocale setLocale:nl_NL];
NSDate *now = [[NSDate alloc] init];
NSString *FormattedYMD = [setDateLocale stringFromDate:now];
[nl_NL release];
[setDateLocale release];
[now release];

And voila, FormattedYMD now holds the current datestamp formatted as: ma, 6 apr 2010

Tagged with:
preload preload preload