How do I get the current date?
Use NSDate and NSDateFormatter.
NSDate *today = [NSDate date];NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];[dateFormat setDateFormat:@"dd/MM/yyyy"];NSString *dateString = [dateFormat stringFromDate:today];NSLog(@"date: %@", dateString);
Break it down.
How do I get the current date? See NSDate.
How do I format a date in a specific format? See NSDateFormatter.
Here is a method to retrieve the current date and print as a string using Swift on IOS 9
let formatter : NSDateFormatter = NSDateFormatter() formatter.dateFormat = "d/M/yy" let myStr : String = formatter.string(from: NSDate.init(timeIntervalSinceNow: 0) as Date) print(myStr)
XCode Debug Print
5/6/16