Re: Two digit dates with NSDateFormatter
Re: Two digit dates with NSDateFormatter
- Subject: Re: Two digit dates with NSDateFormatter
- From: Andreas Mayer <email@hidden>
- Date: Thu, 8 Oct 2009 19:45:16 +0200
Am 08.10.2009 um 15:07 Uhr schrieb Matthew Lindfield Seager:
Am I missing something obvious? Is this a bug?
No idea. This works for me:
- (IBAction)convertTextToDate:(id)sender
{
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setLocale:[NSLocale currentLocale]];
[formatter setTwoDigitStartDate:[[NSCalendar gregorianCalendar]
dateFromYear:1950 month:1 day:1]];
// uses two convenience methods defined elsewhere - semantics should
be obvious
[formatter setDateStyle:NSDateFormatterShortStyle];
NSString *input = [sender stringValue];
NSLog(@"input: %@", input);
NSDate *date = [formatter dateFromString:input];
NSLog(@"date: %@", date);
[dateOutput setObjectValue:date];
[formatter release];
}
Note that your input must match the date format(s) specified in your
current language settings. (I was using the german form with '.' as
divider and input values with '/' did not work.)
Andreas
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden