Convert NSTimeInterval to NSString in iPhone?

Warrior picture Warrior · Nov 25, 2010 · Viewed 41.2k times · Source

How to covert the NSTimeInterval to NSString? I have

NSTimeInterval  today = [[NSDate date] timeIntervalSince1970];

I have to give "today" as input as NSString.

Answer

Vladimir picture Vladimir · Nov 25, 2010

NSTimeInterval is just a double type so you can convert it to string using +stringWithFormat: method

NSTimeInterval  today = [[NSDate date] timeIntervalSince1970];
NSString *intervalString = [NSString stringWithFormat:@"%f", today];