cocoa: how can i convert nsdate to nstimeinterval in cocoa?

cocoa

Solution

`NDDate` and `NSTimeInterval` are two diferent things, you cannot convert a `NSDate` to a `NSTimeInterval` and vice-versa.

`NSDate` represents an absolute date and `NSTimeInterval` represents the time between two dates.

However you can create a NSTimeInterval from a reference date with this method:

- (NSTimeInterval)timeIntervalSinceDate:(NSDate *)anotherDate

You can do it like this:

NSDate *referenceDate = /* Your reference date */
NSDate *date = /* Your date */
NSTimeInterval timeInterval = [date timeIntervalSinceDate:referenceDate];

Problem

``` NSDate *newDate=[newDate dateByAddingTimeInterval:difference]; ``` Now I want to convert this newDate to NStimeInterval. How can I do this conversion?

Original source