• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Two digit dates with NSDateFormatter
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Two digit dates with NSDateFormatter (From: Matthew Lindfield Seager <email@hidden>)
 >Re: Two digit dates with NSDateFormatter (From: Matthew Lindfield Seager <email@hidden>)

  • Prev by Date: Animate a UIImageView's animatingImages?
  • Next by Date: Re: NSWorkspaceDidMountNotification not firing on Snow Leopard
  • Previous by thread: Re: Two digit dates with NSDateFormatter
  • Next by thread: self release
  • Index(es):
    • Date
    • Thread