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
?