Question: how to calculate time difference in swift?
Answer: Calculate time difference in Swift 4. func calcTime(time1: String,time2: String) -> String { let time12 = (String(format: "%02d", time1)) let time22 = (String(format: "%02d", time2)) let time10 = time12. prefix(2) let time20 = time22. prefix(2) print("hours: \(time12)") print("minutes: \(time22)") let time11 = time1.