[英]iOS SDK: How to get the date out of a UIDatePicker?
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. 我需要从UIDatePicker检索日期(最好我也想指定格式。例如,mmdd将输出字符串1209.任何合理解析的字符串也可以。
Thanks in advance. 提前致谢。
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:myDate];
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:myDate];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.