gpt4 book ai didi

ios - 如何以 12 小时格式获取当前时间?

转载 作者:搜寻专家 更新时间:2023-10-31 08:17:48 25 4
gpt4 key购买 nike

我想以 12 小时格式获取当前时间。如果时间是 18:36,我想要格式,那么它应该是 06:35 PM。为此,我使用了下面的代码,但它没有给我所需的格式。我得到这样的格式。

let date = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "h:mm a"
let date22 = dateFormatter.string(from: date)

最佳答案

查看此日期格式 guide . &这个site .

let dateAsString = "6:35 PM"
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "hh:mm a"
let date = dateFormatter.dateFromString(dateAsString)

dateFormatter.dateFormat = "HH:mm"
let date24 = dateFormatter.stringFromDate(date!)

关于ios - 如何以 12 小时格式获取当前时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40807072/

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