gpt4 book ai didi

ios - NSDate 转换为 24 小时格式

转载 作者:行者123 更新时间:2023-11-29 02:47:43 24 4
gpt4 key购买 nike

我希望将我的时间转换为 24 小时格式。

输入:2014-07-23 07:44:47 +0000

输出:19:44:47 <<<我想要这种格式 24 小时

// MY Code
NSLog(@"before %@",selectedDate);
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"hh:mm a"];
NSLog(@"after %@",[dateFormat stringFromDate:selectedDate]);

这就是我得到的: enter image description here

编辑:

还尝试过:[dateFormat setDateFormat:@"HH:mm a"];

结果是:enter image description here

最佳答案

你的代码很好,总能理解这个概念

[dateFormat setDateFormat:@"hh:mm a"];

hh- 12 hour format

HH - 24 hour format


[dateFormat setDateFormat:@"HH:mm a"];

永远记住,K

关于ios - NSDate 转换为 24 小时格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24904735/

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