Objective-C Language NSDate Creating an NSDate

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

The NSDate class provides methods for creating NSDate objects corresponding to a given date and time. An NSDate can be initialized using the designated initializer, which:

Returns an NSDate object initialized relative to 00:00:00 UTC on 1 January 2001 by a given number of seconds.

NSDate *date = [[NSDate alloc] initWithTimeIntervalSinceReferenceDate:100.0];

NSDate also provides an easy way to create an NSDate equal to the current date and time:

NSDate *now = [NSDate date];

It is also possible to create an NSDate a given amount of seconds from the current date and time:

NSDate *tenSecondsFromNow = [NSDate dateWithTimeIntervalSinceNow:10.0];


Got any Objective-C Language Question?