Thursday, June 9, 2011

Convert TimeStamp to NSDate in Objective-C

Here is a code piece which lets you convert the unix type timestamp to Formatted Date


    
    NSString * timeStampString =@"1304245000";
    NSTimeInterval _interval=[timeStampString doubleValue];
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:_interval];
    NSDateFormatter *_formatter=[[NSDateFormatter alloc]init];
    [_formatter setDateFormat:@"dd.MM.yyyy"];
    NSString *_date=[_formatter stringFromDate:date];


This will print  _date something like 05.03.2011

2 comments: