Madhu Madhu - 11 months ago 48
Objective-C Question

Converting into date.How can this be done in objective c?

How to convert 1474914600000 in the following formate

How can this be done in objective c?

Answer Source

You need to convert your timestamp to NSDate and then get NSDate in your desired format. Also your timestamp seems to be in millisecond so you will have to divide it be 1000. You can use below code:

 double timeStamp = 1474914600000;
 NSTimeInterval timeInterval=timeStamp/1000;
 NSDate *date = [NSDate dateWithTimeIntervalSince1970:timeInterval];
 NSDateFormatter *dateformatter=[[NSDateFormatter alloc]init];
 [dateformatter setDateFormat:@"dd-MM-yyyy"];
 NSString *dateString=[dateformatter stringFromDate:date];

dateString value as an output will be: "27-09-2016"

Hope it helps.