从斯威夫特的字符串到NSDate [英] From String to NSDate in Swift
本文介绍了从斯威夫特的字符串到NSDate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个字符串
,包含一个日期
,格式如下:
Thu ,04 Sep 2014 10:50:12 +0000
I've got a string
containing a date
in this format:
Thu, 04 Sep 2014 10:50:12 +0000
你知道如何将其转换为:
04-09 -2014
( dd-MM-yyyy )
Do you know how can I convert it to: 04-09-2014 (dd-MM-yyyy)
当然,使用 Swift
谢谢
of course, using Swift Thanks
推荐答案
如果上述不起作用,这应该是诀窍:
If the above doesn't work, this should do the trick:
let formatter = DateFormatter()
formatter.locale = Locale(identifier: "US_en")
formatter.dateFormat = "E, dd MMM yyyy HH:mm:ss Z"
let date = formatter.date(from: "Thu, 04 Sep 2014 10:50:12 +0000")
这篇关于从斯威夫特的字符串到NSDate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文