I have save the timestamp in data base like:
"NSDate()" // which save Date like this: 2017-03-10 22:53:30 +0000
Now i need to get Date from this string, I have tried every format but it's keep returning nil.
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd hh:mm:ss ZZZ"
dateFormatter.locale = Locale(identifier: "en_US")
print(dateFormatter.date(from: "2017-03-10 22:53:30 +0000") ?? "No Value") // always return No Value
here i have tried so many formats e.g: yyyy-MM-dd hh:mm:ss +zzzz yyyy-MM-dd hh:mm:ss xx
Have seen many answers but no answer is working on this format of date "2017-03-10 22:53:30 +0000"
I am using this code while converting
String
toDate
. (Swift 3)and just call like . .
hh
is a 12-hour hours. You needHH
if you have a 24-hour hour padding. Check http://nsdateformatter.com for more details about NSDateFormatter formats.Military time (24-value hours) uses the capital 'H'. Try this for your formatting String: