Re: Current Hour & Minutes
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