gpt4 book ai didi

ios - 快速格式化字符串中的日期

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

<分区>

我有以下日期来自服务器 2019-09-05T10:37:49.494Z 作为字符串,我需要解析它并将其转换为这样的格式 Fri September 13,2019 12:36 AM 再次回到字符串:我找到了多个问题链接,但没有一个对我有用 Question One Question Two

它尝试这样做:

let dateFormatterGet = DateFormatter()
let dateFormatterPrint = DateFormatter()
var rawDate = "2019-09-05T10:37:49.494Z"

dateFormatterGet.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ"
dateFormatterPrint.dateFormat = "E, d MMM yyyy HH:mm"
var formattedDate = "Error Formatting date"
if let date = dateFormatterGet.date(from: rawDate) {
formattedDate = dateFormatterPrint.string(from: date)
print("Formatted Date : \(formattedDate)")
}else {
print("There was an error decoding the string")
}

打印错误消息失败,我做错了什么,我该如何解决?

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