Tag Archives: NSDateFormatter

Objective-C – Display Date and Time Using NSDateFormatter

You can get the Date and Time in NSString using NSDateFormatter.

// Get current datetime
NSDate *currentDateTime = [NSDate date];

// Instantiate a NSDateFormatter
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];

// Set the dateFormatter format
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];

// Get the date time in NSString
NSString *dateInString = [dateFormatter stringFromDate:currentDateTime];

// Release the dateFormatter
[dateFormatter release];

Continue reading Objective-C – Display Date and Time Using NSDateFormatter