Andrew
Andrew

Reputation: 708

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?

Upvotes: 4

Views: 13050

Answers (5)

Dhiru
Dhiru

Reputation: 3060

This give the Current date

NSDate *curentDate=[NSDate date];

Upvotes: 0

Dinesh Reddy Chennuru
Dinesh Reddy Chennuru

Reputation: 491

use NSDate *currentTime=[NSDate date]; and use NSDateFormatter class object to convert the time to your time format.

Upvotes: 0

8vius
8vius

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

justin
justin

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

Jordaan Mylonas
Jordaan Mylonas

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

Related Questions