Megha Megha - 5 months ago 10
iOS Question

What is the Date format

What is the date and time format for "06/08/2016 09:50:12" to be converted to "dd MMMM YYYY HH:mm"?, which i'm converting the NSDate to NSString.

Answer

Try this,

    NSString *strDate = @"06/08/2016 09:50:12";
    NSDateFormatter *format= [[NSDateFormatter alloc] init];
    [format setDateFormat:@"dd/MM/YYYY HH:mm:s"];
    NSDate *date = [format dateFromString:strDate];
    NSLog(@"%@",date);

To convert this date into string :

    NSDateFormatter *format = [[NSDateFormatter alloc] init];
    [format setDateFormat:@"dd/MM/YYYY HH:mm:s"];
    NSString *str = [format stringFromDate:date];

Hope this help

Comments