hellosheikh
hellosheikh

Reputation: 3015

How to show Month and also weekday in three letters from date

Hello I am getting a date from server like this

2016-02-10

and I want to show a date on my view like this

 TUE, 10 FEB 2016

How can I do this

here is my code of getting a date

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

Upvotes: 2

Views: 2050

Answers (1)

Anbu.Karthik
Anbu.Karthik

Reputation: 82759

do like

//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 format strings are in Unicode format.

Upvotes: 4

Related Questions