Madhu Madhu - 6 months ago 23
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?


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.