[Swift 4.2] How to change Time String to seconds Integer
If you have time data in the form of a string format and want to change it to the second form to make a stopwatch, then you can follow this method below.
let greeting = "12:14:57"
let words = greeting.split(separator: ":")
let toBe = Int(words[0])
let toBe1 = Int(words[1])
let toBe2 = Int(words[2])
let be = toBe! * 60 * 60
let be1 = toBe1! * 60
let be2 = toBe2! + be1 + be
print("\(words[0]), \(words[1]), \(words[2])")
print("hasilnya: \(be2)")
No comments: