gpt4 book ai didi

iphone - iOS SDK : How to get the date out of a UIDatePicker?

转载 作者:行者123 更新时间:2023-12-03 18:23:05 24 4
gpt4 key购买 nike

我需要从 UIDatePicker 检索日期(最好我也希望指定格式。例如,mmdd 将输出字符串 1209。任何合理解析的字符串都可以工作。

提前致谢。

最佳答案

您需要使用日期属性:

NSDate *myDate = datePicker.date;

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

顺便说一句,这并不明显,但您可以通过将其包含在单引号内来添加特定的未解析文本,格式如下:

[dateFormat setDateFormat:@"'Game-'yyyyMMdd-HHmm'.xml'"];
NSString *filenameVersion = [dateFormat stringFromDate:myDate];

关于iphone - iOS SDK : How to get the date out of a UIDatePicker?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1627292/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com