如何在日期

时间:2016-02-10 10:02:00

标签: ios swift

您好我从服务器那里得到了这样的日期

2016-02-10

我想在我的观点上显示一个日期

 TUE, 10 FEB 2016

我该怎么做

这是我获取日期的代码

let departureDate  = (((dict["\(indexPath.item)"] as?NSDictionary)!["Trip"] as?NSDictionary)!["departure_date"] as?NSString)! as String

1 个答案:

答案 0 :(得分:1)

喜欢

//create dateformatter
let dateFormatter2 = NSDateFormatter()

// set your dateformat intially whatever u get from server or local
                          //2016-02-10
dateFormatter2.dateFormat = "yyyy-MM-dd"

// convert your string to date
let date2 = dateFormatter2.dateFromString(departureDate as String)

 // create another dateformat for what output u need at final
                           // TUE, 10 FEB 2016
 dateFormatter2.dateFormat = "EEE, dd MMM yyyy"
 // again convert the date to string again 
 let finaldate = dateFormatter2.stringFromDate(date2!).uppercaseString

iPhone格式字符串位于Unicode format