将日期字符串转换为"yyyy/mm/dd hh:mm:ss"Android&中的格式迅速 [英] Convert a date String to "yyyy/mm/dd hh:mm:ss" format in Android & Swift
本文介绍了将日期字符串转换为"yyyy/mm/dd hh:mm:ss"Android&中的格式迅速的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在从服务器获取这种格式的字符串
I am getting a String in this format from the server
2015-06-18T05:05:00.880483Z
我需要将此格式转换为 yyyy/mm/dd hh:mm:ss
格式,该格式应为字符串.如何在 Android
和 Swift-iOS
中实现此目的.如果您知道如何在一个平台上执行此操作,请提供帮助.预先感谢.
I need to convert this to yyyy/mm/dd hh:mm:ss
format, which should be a string. How can I achieve this in Android
as well as Swift-iOS
. Please help if you know how to do this in one platform. Thanks in advance.
推荐答案
let stringDate = "2015-06-18T05:05:00.880483Z"
let df = NSDateFormatter()
df.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSSSSZ"
if let date = df.dateFromString(stringDate) {
df.dateFormat = "yyyy/MM/dd HH:mm:ss"
let finalString = df.stringFromDate(date)
println(finalString)
}
这篇关于将日期字符串转换为"yyyy/mm/dd hh:mm:ss"Android&中的格式迅速的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文