Convert string to date in Swift
How can I convert this string "2016-04-14T10:44:00+0000" into an NSDate and keep only the year, month, day, hour? The T in the middle of it really throws off what I am used to when working with dates. Convert the ISO8601 sting to date let isoDate = "2016-04-14T10:44:00+0000" let dateFormatter = DateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ" dateFormatter.locale = Locale(identifier: "en_US_POSIX") // set locale to reliable US_POSIX let date = dateFormatter.date(from:isoDate)! Get the date components for year, month, day and hour from the date let calendar = Calendar.current