【发布时间】:2018-10-03 06:46:59
【问题描述】:
我想获得这种类型的甲酸盐 -> 2018 年 4 月 20 日晚上 9:02:00 UTC+5:30 对于 Firestore 时间戳。我已经尝试过这段代码,但没有像上面那样得到正确的甲酸盐。
let date = Date()
let formatter = DateFormatter()
formatter.dateFormat = "MMMM d yyyy hh:mm:ss a Z"
formatter.timeZone = NSTimeZone(name: "IST") as TimeZone?
let result = formatter.string(from: date)
print(result)
已经使用这个格式化程序 formatter.dateFormat = "MMMM d yyyy'T'hh:mm:ss a Z"
谢谢
【问题讨论】:
-
"已经尝试过这段代码,但没有得到上述正确的甲酸盐。"它给了你什么?例如,我在您的格式中看不到
'at'。 -
确定需要在中间加上“at”吗?
-
是的@AbhirajsinhThakore
-
@Rock 一个建议,将
timeStamp保存为 unix 格式,如 this1524476327并在客户端解析它以用于 UI 目的。 -
不知道为什么每个
dateFormat的新问题有多种格式,因此每当需求更改时,您都会提出新问题。为什么不只用谷歌搜索那种特定的格式?
标签: ios swift dateformatter