Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the time in iOS Programming

I wanted to get random numbers according to time. How do you get the current time in iOS Programming for the iPhone?

like image 987
Andrew Avatar asked Nov 29 '22 16:11

Andrew


2 Answers

NSDate *now = [[NSDate alloc] init]; OR NSDate *now = [NSDate date];
an NSDate object by default will be initialised to the current date.

like image 197
Jordaan Mylonas Avatar answered Dec 09 '22 16:12

Jordaan Mylonas


in addition to the existing answers:

gettimeofday for high accuracy

or

CFAbsoluteTimeGetCurrent if you want a fairly high level interface without an object.

like image 26
justin Avatar answered Dec 09 '22 16:12

justin