Anand Anand - 1 month ago 4x
iOS Question

Convert 1347616929 into dd/MM/yyyy hh:mm:ss format

I have a date time in milliseconds, e.g. 1347616929, and I want to convert it to get the date and time in a "dd/MM/yyyy hh:mm:ss" format.


First of all, you have to convert miliseconds in to seconds by dividing miliseconds by 1000.

   NSTimeInterval timeInSecond = 1347616929/1000;
   NSDate *date = [NSDate dateWithTimeIntervalSince1970:timeInSecond];
   NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
   [formatter setDateFormat:@"dd/MM/yyyy HH:mm:ss"];
   NSString *formattedDate=[formatter stringFromDate:date];
   NSLog(@"Formatted Date : %@",formattedDate);