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

Re: Rounding an NSDate down


  • Subject: Re: Rounding an NSDate down
  • From: "Jim Thomason" <email@hidden>
  • Date: Fri, 7 Dec 2007 21:12:25 -0600

You shouldn't need to convert to an NSString. NSCalendarDates are
NSDates, so you should just be able to pass in an NSCalendarDate
wherever an NSDate is requested.

//broken up into multiple ops for clarity
NSCalendarDate* calendarDate = [myDate dateWithCalendarFormat:nil timeZone:nil];
NSCalendarDate* roundedDate = [calendarDate dateByAddingYears: 0
    months: 0
    days: 0
    hours: 0
    minutes: - [calendarDate minuteOfHour]
    seconds: 0];

[someObject doNeatThingWithDate:roundedDate];

-Jim.....

On Dec 7, 2007 8:42 PM, Todd Ransom <email@hidden> wrote:
> I cannot seem to figure out any way to round down a date without a lot
> of messy conversion to NSCalendarDates and NSStrings and back to an
> NSDate, which seems like it would be error prone.
>
> If I have a date like this:
>
> 01/01/2007 12:30 PM
>
> I want to round it down to the nearest hour, basically just dropping
> the minutes so it ends up like this:
>
> 01/01/2007 12:00 PM
>
> Does anyone know of an easy way to do this?
>
> Todd Ransom
> Return Self Software
> http://returnself.com
>
>
>
> _______________________________________________
>
> 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
>
_______________________________________________

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: Rounding an NSDate down
      • From: Todd Ransom <email@hidden>
References: 
 >Rounding an NSDate down (From: Todd Ransom <email@hidden>)

  • Prev by Date: Re: Rounding an NSDate down
  • Next by Date: Re: Class lookup at runtime
  • Previous by thread: Re: Rounding an NSDate down
  • Next by thread: Re: Rounding an NSDate down
  • Index(es):
    • Date
    • Thread