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

Re: NSDate


  • Subject: Re: NSDate
  • From: p3consulting <email@hidden>
  • Date: Thu, 5 Feb 2004 07:31:56 +0100

NSCalendardDate has

- (id)initWithString:(NSString *)description
- (id)initWithString:(NSString *)description calendarFormat:(NSString
*)format
- (id)initWithString:(NSString *)description calendarFormat:(NSString
*)format locale:(NSDictionary *)locale

NSDate has

- (NSCalendarDate *)dateWithCalendarFormat:(NSString *)formatString
timeZone:(NSTimeZone *)timeZone

and

- (NSComparisonResult)compare:(NSDate *)anotherDate

NSCalendarDateDate *aDate = [[NSCalendarDateDate alloc]
initWithString:theString] calendarFormat:@"%d/%m/%y"] ;

// or %m/%d%y or %y/%m/%d or %y/%d/%m or 
// provided example doesn't tell
// see
// file:/Developer/Documentation/Cocoa/Conceptual/DataFormatting/Tasks/
SettingFormatForDates.html
// for more info on format strings

switch ([aDate compare:theOtherDate]) {
...

The main question would be: are the input strings all in the same
format and do you know it or the application has the guess it from
input ?
If the input is from a NSTextField you better had a NSDateFormater to
the text field with the accepted format and directly ask for the NSDate
to the formater ([ibMyDateField objectValue] and not [ibMyDateField
stringValue]...).
If the input is from imported text files, either you ask the user,
either you work with two pass, keeping the original text in memory,
converting each entry to the 6 possibilities, counting the errors for
each version, and suggesting the one with the min of errors when you
are done reading the file

Pascal Pochet
P3 Consulting


On 5 fivr. 2004, at 06:39, April Gendill wrote:

> Is it possible to take a string such as 2/04/04 and compare it to an
> NSDate object?
>
> so far I simply cannot seem to get the string into something that
> would allow me to compare or sort or anything.
>
> April
> _______________________________________________
> cocoa-dev mailing list | email@hidden
> Help/Unsubscribe/Archives:
> http://www.lists.apple.com/mailman/listinfo/cocoa-dev
> Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >NSDate (From: April Gendill <email@hidden>)

  • Prev by Date: Re: NSDate
  • Next by Date: Re: Unwanted retain
  • Previous by thread: Re: NSDate
  • Next by thread: Sound manipulation in Cocoa
  • Index(es):
    • Date
    • Thread