gpt4 book ai didi

ios - UILabel 从日期选择器获取日期时的日期格式

转载 作者:行者123 更新时间:2023-11-28 22:41:31 24 4
gpt4 key购买 nike

我有日期选择器、一个按钮和一个标签。标签上写着“选择你的日期”,日期选择器是,是的,一个日期选择器,按钮将用户选择的日期传输到标签中,如下所示:“你选择了日期 2013-01-18 02:28:58 +0000 ".

如何将日期格式设置为:“您选择了日期 18/01-2013”​​???没有设置时间和日/月/年?

我在按钮 IBAction 中用于转移到标签的代码是:

NSString *words = [[NSString alloc]initWithFormat:@"You chose the date %@", dateSelected];
settDato.text = words;

最佳答案

使用NSDateFormatter,在你的.h中有

NSDateFormatter *formatter

然后在viewDidLoad或者init方法中最好

formatter=[[NSDateFormatter alloc] init];
[formatter setDateFormat:@"dd/MM-YYYY"];

然后在你的 IBAction

NSString *words = [NSString stringWithFormat:@"You chose the date %@", [formatter stringFromDate:dateSelected]];
settDato.text = words;

关于ios - UILabel 从日期选择器获取日期时的日期格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14403156/

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