Search code examples
iphoneobjective-cdatetimenstimer

Getting Current Time in string in Custom format in objective c


I want current time in following format in a string.

dd-mm-yyyy HH:MM

How?


Solution

  • You want a date formatter. Here's an example:

    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"dd-MM-yyyy HH:mm"];
    
    NSDate *currentDate = [NSDate date];
    NSString *dateString = [formatter stringFromDate:currentDate];