get time and date by NSDate

NSDate *localDate = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
dateFormatter.dateFormat = @"MM/dd/yy";

NSString *dateString = [dateFormatter stringFromDate: localDate];



NSDateFormatter *timeFormatter = [[NSDateFormatter alloc]init];
timeFormatter.dateFormat = @"HH:mm:ss";


NSString *dateString = [timeFormatter stringFromDate: localDate];

There are many many different ways to represent the date and time so check NSDateFormatter for more info.


i would go with using NSDateComponents and NSCalendar if you really want to have the values for the minute, hour and the date ... Something like this:

NSDateComponents *components = [[NSCalendar currentCalendar] components:NSHourCalendarUnit | NSMinuteCalendarUnit | NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit
                                                                   fromDate:[NSDate date]];

then you can use the properties of the components to access the value of each components with component.hour, component.year, etc.

Also please note that if you are going with the NSDateFormatter example - then you should remember that NSDateFormatter is a heavy object and you should really reuse it if possible ...