• 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
Lenient Date Formatter
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Lenient Date Formatter


  • Subject: Lenient Date Formatter
  • From: "Gerriet M. Denkmann" <email@hidden>
  • Date: Tue, 13 May 2014 21:08:49 +0700

I need a date formatter which can do (10.9.2):

NSDate *d1 = [ dateFormatter dateFromString: @"2014-05-13 11:31:03.943 +0700" ];
NSDate *d2 = [ dateFormatter dateFromString: @"2014-05-13 11:31:03 +0700" ];	//	no fractional seconds

so that both d1 and d2 are non-nil.

Is this possible?

Currently I am using this code (which works, but looks rather clumsy):

NSDateFormatter *dateFormatter1 = [ [ NSDateFormatter alloc ] init];
[ dateFormatter1 setDateFormat: @"yyyy-MM-dd HH:mm:ss ZZZ" ];	//	no fractional seconds

NSDateFormatter *dateFormatter2 = [ [ NSDateFormatter alloc ] init];
[ dateFormatter2 setDateFormat: @"yyyy-MM-dd HH:mm:ss.SSS ZZZ" ];

NSDate *dat = [ dateFormatter1 dateFromString: someString ];
if ( dat == nil ) dat = [ dateFormatter2 dateFromString: someString ];

setLenient: YES seems not to be helpful.

Gerriet.


_______________________________________________

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


  • Follow-Ups:
    • Re: Lenient Date Formatter
      • From: Jens Alfke <email@hidden>
  • Prev by Date: Re: Share and store RSA - public key in java server and vice versa
  • Next by Date: Re: Share and store RSA - public key in java server and vice versa
  • Previous by thread: Re: Share and store RSA - public key in java server and vice versa
  • Next by thread: Re: Lenient Date Formatter
  • Index(es):
    • Date
    • Thread