Convert Date String to Int Swift

后端 未结 3 1387
时光取名叫无心
时光取名叫无心 2021-01-19 14:39

I am trying to convert the string:

let time = \"7:30\"

to integers:

let hour : Int = 7
let minutes : Int = 30
3条回答
  •  难免孤独
    2021-01-19 15:21

    You can split string by : character and then convert results to Int:

    let timeStringArray = time.componentsSeparatedByString(":")
    if timeStringArray.count == 2 {
       hour = timeStringArray[0].toInt
       minutes = timeStringArray[1].toInt()
    }
    

提交回复
热议问题