0

I'm trying to show current server time if the user type any site name. And time should keep going every second.

I could get specific server time using Alamofire.

if let headers = result?.allHeaderFields {
    if let date = headers["Date"] as? String {
        let formatter = NSDateFormatter()
        formatter.dateFormat = "E, dd MMM yyyy HH:mm:ss Z"
        formatter.locale = NSLocale.currentLocale()
        currentTime.text = formatter.dateFromString(date)
    }
}

in constant date , there is a value "Sun, 20 Mar 2016 13:31:08 GMT" type of String.

I'm trying to change this value to NSDate type to change date format and locale.

It gives an error

Can not assign value of type 'NSDate' to type 'String'.

How can I put NSDate type to currentTime.text?

nhgrif
  • 61,578
  • 25
  • 134
  • 173
alphonse
  • 687
  • 1
  • 6
  • 16

1 Answers1

0

You are using NSDateFormatter to convert date from String to NSDate, so you need another NSDateFormatter to convert date from NSDate back to String using new date format.