Reputation: 61
I have datepicker, a button and a label. The label says "Choose your date", the datepicker is, yeah, a datepicker and the button transfers the date the user picked into the label, like this: "You chose the date 2013-01-18 02:28:58 +0000".
How can I get the date format to be: "You chose the date 18/01-2013" ??? Without the time and the day/month/year set up?
The code I have in the button IBAction for the transfer to label is:
NSString *words = [[NSString alloc]initWithFormat:@"You chose the date %@", dateSelected];
settDato.text = words;
Upvotes: 0
Views: 1169
Reputation: 2064
Use NSDateFormatter
, in your .h
have
NSDateFormatter *formatter
Then in viewDidLoad
or init
method is best
formatter=[[NSDateFormatter alloc] init];
[formatter setDateFormat:@"dd/MM-YYYY"];
Then in your IBAction
NSString *words = [NSString stringWithFormat:@"You chose the date %@", [formatter stringFromDate:dateSelected]];
settDato.text = words;
Upvotes: 2