I wanted to get random numbers in time. How do you get the current time in iOS Programming for iPhone?
NSDate *now = [[NSDate alloc] init]; OR The NSDate *now = [NSDate date];NSDate will default to the current date.
NSDate *now = [[NSDate alloc] init];
NSDate *now = [NSDate date];
in addition to existing answers:
gettimeofday for high precision
gettimeofday
or
CFAbsoluteTimeGetCurrentif you want a fairly high level interface without an object.
CFAbsoluteTimeGetCurrent
,
, , , iOS- , , , iTunes Store Stanford iTunes U iOS
use NSDate *currentTime=[NSDate date];and use the class object NSDateFormatterto convert time to time format.
NSDate *currentTime=[NSDate date];
NSDateFormatter
It gives the current date
NSDate *curentDate=[NSDate date];