gpt4 book ai didi

ios - swift 如何转换时间字符串 +4 :00 to Timezone

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

如何将字符串转换为时区?例如,我有字符串:

2016.9.5 - 16:36

此时是GMT+4,那么如何转换为时区呢?

最佳答案

首先从上面的字符串中删除'-'然后将字符串传递给下面的方法

static func getDateFromString( _ str  : String) -> Date{
let dateFormatter = DateFormatter()
dateFormatter.timeZone = TimeZone(abbreviation: "GMT")
dateFormatter.dateFormat = "yyyy.MM.dd HH:mm"
return dateFormatter.date(from: str)!
}

关于ios - swift 如何转换时间字符串 +4 :00 to Timezone,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48982834/

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