Converting String to NSDate Giving Wrong Date

你。 提交于 2019-11-28 14:40:30

You are using the wrong format. You need dd MMM yyyy.

To use correct format string is most important..

YYYY is week-based calendar year. (used in ISO week-year calendar)

yyyy is ordinary calendar year.

so, You should use 'yyyy' instead of 'YYYY'.

let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "dd MMM yyyy"

print(birthday)  

let date = dateFormatter.dateFromString(birthday)
self.datePicker.setDate(date!, animated: true)

For more string format for Date: refer this link

https://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.110).aspx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!