Swift 4 "Change String to Date without time"
Converting Date String to Date change format, and after that convert again to String Type with Swift
let isoDate = "2018-07-26"
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-M-d"
dateFormatter.locale = Locale(identifier: "en_US_POSIX") // set locale to reliable US_POSIX
let date = dateFormatter.date(from:isoDate)!
let calendar = Calendar.current
let components = calendar.dateComponents([.year, .month, .day], from: date)
let finalDate = calendar.date(from:components)
print("cek4:\(String(describing: finalDate))")
dateFormatter.dateFormat = "dd MMMM yyyy"
let newDate = dateFormatter.string(from: finalDate!)
print("cek5:\(String(describing: newDate))")
in look PlayGround
Swift 4 "Change String to Date without time"
Reviewed by Luffyselah
on
July 30, 2018
Rating: 5
