Objective-C NSDate

April 10, 2009 § Leave a comment

NSDate is an abstract class to create dates, comparing dates, formatting dates, computing intervals, etc.

NSDate offers methods to display dates in string (dateWithNaturalLanguageString:locale: and descriptionWithLocale:).

Create a current date:
NSDate *today = [NSDate date];

dateWithTimeIntervalSince1970:
Create NSDate object to given no. of sec from the first instant of 1 Jan 1970, GMT.
+ (id)dateWithTimeIntervalSince1970:(NSTimeInterval)seconds

dateWithTimeIntervalSinceNow:
Create NSDate object to given no. of sec from the current date and time.
+ (id)dateWithTimeIntervalSinceNow:(NSTimeInterval)seconds

Methods
Add no. of sec to the receiver. Use a negative value for sec to get a date earlier than the receiver
– (id)addTimeInterval:(NSTimeInterval)seconds

description
The receiver in string in international format YYYY-MM-DD HH:MM:SS ±HHMM, where ±HHMM represents the time zone offset in hours and minutes from GMT (for example, “2001-03-24 10:45:32 +0600”).
-(NSString *)description

timeIntervalSinceNow
– (NSTimeInterval)timeIntervalSinceNow

timeIntervalSinceDate
– (NSTimeInterval)timeIntervalSinceDate:(NSDate *)anotherDate

timeIntervalSince1970
– (NSTimeInterval)timeIntervalSince1970

timeIntervalSinceReferenceDate
– (NSTimeInterval)timeIntervalSinceReferenceDate

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

What’s this?

You are currently reading Objective-C NSDate at Web Builders.

meta

%d bloggers like this: