• 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: Nick Zitzmann <email@hidden>
  • Date: Sun, 8 Apr 2007 14:34:45 -0600


On Apr 8, 2007, at 2:15 PM, محمد الركيان wrote:

Hmm, this look easy, but I don't know why it doesn't work with me !!!

All what I need is the current hour & minutes as int.

Try: (warning - written in Mail, untested, use at your own risk, etc.)

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];


Nick Zitzmann
<http://www.chronosnet.com/>




_______________________________________________

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


  • Follow-Ups:
    • Re: Current Hour & Minutes
      • From: Scott Stevenson <email@hidden>
References: 
 >Current Hour & Minutes (From: محمد الركيان <email@hidden>)

  • Prev by Date: Re: Multiple developers and nib files
  • Next by Date: Re: Multiple developers and nib files
  • Previous by thread: Current Hour & Minutes
  • Next by thread: Re: Current Hour & Minutes
  • Index(es):
    • Date
    • Thread