Skip navigation.
 
mlRe: Current Hour & Minutes
FROM : Nick Zitzmann
DATE : Sun Apr 08 22:34:45 2007

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/>

Related mailsAuthorDate
mlCurrent Hour & Minutes ???? ??????? Apr 8, 22:15
mlRe: Current Hour & Minutes Nick Zitzmann Apr 8, 22:34
mlRe: Current Hour & Minutes Scott Stevenson Apr 9, 00:03
mlRe: Current Hour & Minutes Scott Stevenson Apr 9, 00:13