我使用外部的天气api返回json的数据:
{
"results": [
{
"location": {
"name": "北京",
"country": "CN",
"path": "北京,北京,中国",
"timezone": "Asia/Shanghai",
"timezone_offset": "+08:00"
},
"now": {
"text": "晴",
"code": "0",
"temperature": "3"
},
"last_update": "2017-02-17T11:10:00+08:00"
}
]
}
我获取到更新时间 2017-02-17T11:10:00+08:00 字符串
请问: 我想讲这个获取的更新时间转换成自定义格式的 2017年2月17日 11:10 这样的格式,应该怎么写?我用 swift 3
if let updateTime = resultDict["last_update"] as? String {
//时间字符串已经获取到 updateTime ,这里需要将字符串格式化...
//下面我将时间连接显示到app的界面UILabel上
updateInfo.text = updateTime
}
谢谢!
将格式设置为需要的样子就可以格式化了,希望对你有帮助