Answers for "change string to date in swift 5"

3

swift stirng to date

let isoDate = "2016-04-14T10:44:00+0000"

let dateFormatter = DateFormatter()
dateFormatter.locale = Locale(identifier: "en_US_POSIX") // set locale to reliable US_POSIX
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ"
let date = dateFormatter.date(from:isoDate)!

let calendar = Calendar.current
let components = calendar.dateComponents([.year, .month, .day, .hour], from: date)

let finalDate = calendar.date(from:components)
Posted by: Guest on December-21-2020
2

change from Date to String swift 5

let formatter = DateFormatter()
formatter.dateFormat = "HH:mm E, d MMM y"
print(formatter.string(from: today))
Posted by: Guest on May-31-2021

Code answers related to "Swift"

Browse Popular Code Answers by Language