tags:

views:

139

answers:

1

I need to retrieve the date from a UIDatePicker (Preferably I would also like to be specify the format as well. For example, mmdd would output the string 1209. Any string that reasonably parsed would work as well.

Thanks in advance.

+2  A: 

You need to use the date property:

NSDate *myDate = datePicker.date;

NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"cccc, MMM d, hh:mm aa"];
NSString *prettyVersion = [dateFormat stringFromDate:parsedDate];

BTW, it's not obvious but you can add specific non-parsed text by encompassing it inside single quotes in the format:

[dateFormat setDateFormat:@"'Game-'yyyyMMdd-HHmm'.xml'"];
NSString *filenameVersion = [dateFormat stringFromDate:parsedDate];
Epsilon Prime
Works great. Thank you.
jp chance