Reputation: 708
I wanted to get random numbers according to time. How do you get the current time in iOS Programming for the iPhone?
Upvotes: 4
Views: 13050
Reputation: 491
use NSDate *currentTime=[NSDate date];
and use NSDateFormatter
class object to convert the time to your time format.
Upvotes: 0
Reputation: 5836
It is actually very simple, refer to this dev document
Also, you seem fairly new to iOS dev and seem to be having problems on basic things, I would suggest downloading from the iTunes Store the Stanford iTunes U iOS programming course
Upvotes: 4
Reputation: 104698
in addition to the existing answers:
gettimeofday
for high accuracy
or
CFAbsoluteTimeGetCurrent
if you want a fairly high level interface without an object.
Upvotes: 6
Reputation: 1271
NSDate *now = [[NSDate alloc] init];
OR NSDate *now = [NSDate date];
an NSDate object by default will be initialised to the current date.
Upvotes: 11