gpt4 book ai didi

Ios Swift 日期从时区转换

转载 作者:行者123 更新时间:2023-11-30 11:19:00 25 4
gpt4 key购买 nike

 dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss"
dateFormatter.timeZone = TimeZone(abbreviation: "KST")
let nowstring = dateFormatter.string(from: Date())
let nowdate = dateFormatter.date(from: nowstring)
print(nowstring)
print(nowdate)

打印此2018-07-24T15:06:26
可选(2018-07-24 06:06:26 +0000)

我想要现在日期值2018-07-24T15:06:26

但是没有时区的字符串到日期

我必须使用timeIntervalSince所以nowdate必须有时区

最佳答案

let today = NSDate()
print("\(today)")


let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
let nowDatestring = formatter.string(from: today)

formatter.timeZone = TimeZone(abbreviation: "KST")
let kstDate = formatter.date(from: nowDatestring)
print("\(kstDate!)")


formatter.timeZone = TimeZone(abbreviation: "PST")
let pstDate = formatter.date(from: nowDatestring)
print("\(pstDate!)")


formatter.timeZone = TimeZone(abbreviation: "IST")
let istDate = formatter.date(from: nowDatestring)
print("\(istDate!)")

关于Ios Swift 日期从时区转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51491592/

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