How do I get the current date?

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

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.


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

Need Your Help

Twitter Search API is returning weird characters - is it me or is it them?

twitter character-encoding jsonp

We are building an app that accesses the Twitter search over JSONP.

BigDecimal methods send formatted numbers

java rounding bigdecimal

I'm trying to round my big BigDecimals off to three decimal places. For instance, let's say I have some