Get the current time and date in iOS and set the format. The current time in ios
Get current time
NSDate * timeDate = [NSDatedate];
NSDateFormatter * dateformatter = [[NSDateFormatteralloc] init];
[DateformattersetDateFormat: @ "HH: mm: ss"];
// [Dateformatter setDateFormat: @ "HH-mm-ss"];
NSString * locationString = [dateformatter stringFromDate: timeDate];
TextField. text = locationString;
Get current date
NSCalendar * cal = [NSCalendar currentCalendar];
NSUInteger unitFlags = NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit;
NSDateComponents * conponent = [cal components: unitFlags fromDate: timeDate];
NSInteger year = [conponent year];
NSInteger month = [conponent month];
NSInteger day = [conponent day];
NSString * nsDateString = [NSString stringWithFormat: @ "% 4ld year % 2ld month % 2ld day", year, month, day];
TextField. text = nsDateString;