Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the current date?

Tags:

How can I get the current date, and format it like "20/12/2010"?

like image 835
Mat Avatar asked Jan 20 '10 13:01

Mat


People also ask

How do I display the current date in a text box?

Note: To insert only the current date into the textbox, please enter this formula: =Text(today(),"dd/mm/yyyy") into the linked cell A1.


2 Answers

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); 

See also.

like image 50
martin clayton Avatar answered Sep 28 '22 06:09

martin clayton


Break it down.

How do I get the current date? See NSDate.

How do I format a date in a specific format? See NSDateFormatter.

like image 39
Mike Abdullah Avatar answered Sep 28 '22 06:09

Mike Abdullah