• 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: Scott Anguish <email@hidden>
  • Date: Thu, 5 Feb 2004 01:50:11 -0500

On Feb 5, 2004, at 1:01 AM, Laurent Daudelin wrote:

> on 05/02/04 00:39, April Gendill at email@hidden 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.
>>
>
> NSCalendarDate *firstDate = [NSCalendarDate dateWithString:aString
> calendarFormat:[[NSUserDefaults standardUserDefaults]
> objectForKey:NSShortDateFormatString]];
>
> if ([firstDate earlierDate:secondDate] == firstDate)
> [self doSomething];
>
>

NSCalendarDate also includes time, so unless the NSDate that is
preexisting is in the same time-zone, and has the same time specified
as is provided by NSCalendarDate when no time is in the string, that's
not going to work reliably.

One solution might be to convert the string to a sortable format of a
date (YYYY-MM-DD), and then have a category on NSDate return a string
formatted similarly, and then you could sort/compare those with the
usual string beasties.

[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
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.

  • Follow-Ups:
    • Re: NSDate
      • From: Scott Anguish <email@hidden>
References: 
 >Re: NSDate (From: Laurent Daudelin <email@hidden>)

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