JSON时间和格式的时间数据我已经从网站的JSON数据时间的列表排列,所以我需要在24小时制转换时间达到12小时,使用时间,使与当前时间获得从迅速
此相比我的代码: -
let task=URLSession.shared.dataTask(with: url!) {(data, response, err) in
if err != nil{
print("err")
}else{
do{
let dataT=try JSONSerialization.jsonObject(with: data!, options: JSONSerialization.ReadingOptions.mutableContainers) as? NSDictionary
if let prayTime = dataT?["times"] as? NSArray {
if let fajerTT = prayTime[0] as? String {
let timeFormat = DateFormatter()
timeFormat.dateFormat = "hh:mm"
let timeFajer=timeFormat.date(from: fajerTT)
print(fajerTT)
print("\(timeFajer))")
self.fajerT.text=timeFajer
}else {print("false")}
}
}catch{print("Error")
}
}
}
task.resume()
,这从JSON
["05:05","06:30","12:56","16:30","19:21","19:21","20:51"]}
的可能的复制[ xcode swift am/pm time to 24 hours format](https://stackoverflow.com/questions/29321947/xcode-swift-am-pm-time-to-24-hour-format) – BennX
此外:https:///stackoverflow.com/q/36096533/1804251 – BennX
请检查此:https://stackoverflow.com/questions/34360941/convert-an-array-of-times-from-24hr-to-12-hr-in-swift –