• 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: Current Hour & Minutes
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Current Hour & Minutes


  • Subject: Re: Current Hour & Minutes
  • From: Scott Stevenson <email@hidden>
  • Date: Sun, 8 Apr 2007 15:13:03 -0700


On Apr 8, 2007, at 1:34 PM, Nick Zitzmann wrote:

NSCalendarDate *now = [NSCalendarDate date];
int hour = [now hourOfDay];
int minute = [now minuteOfHour];

Alternately, this will work in Tiger and later, and is probably more future-proof:

NSCalendar *cal = [NSCalendar currentCalendar];
NSDateComponents *hourAndMinute = [cal components:NSHourCalendarUnit | NSMinuteCalendarUnit fromDate: [NSDate date]];
int hour = [hourAndMinute hour];
int minute = [hourAndMinute minute];

For what it's worth, THCalendarInfo (which the original poster was using) already uses CFCalendar, which should be future-proof:


+ (int) currentHourIn24HourFormat
{
        CFCalendarRef myCalendar = CFCalendarCopyCurrent();
	int myHour = CFCalendarGetOrdinalityOfUnit (
	   myCalendar,
	   kCFCalendarUnitHour,
	   kCFCalendarUnitDay,
	   [self currentAbsoluteTime]
	);


// adjust for real-world expectations // otherwise, 3:45 is '4' (fourth hour) myHour--; if ( myCalendar ) CFRelease( myCalendar ); return myHour; }

   - Scott
_______________________________________________

Cocoa-dev mailing list (email@hidden)

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: 
 >Current Hour & Minutes (From: محمد الركيان <email@hidden>)
 >Re: Current Hour & Minutes (From: Nick Zitzmann <email@hidden>)

  • Prev by Date: Re: Current Hour & Minutes
  • Next by Date: Re: Points
  • Previous by thread: Re: Current Hour & Minutes
  • Next by thread: Re: Current Hour & Minutes
  • Index(es):
    • Date
    • Thread