Xcode swift am/pm time to 24 hour format

后端 未结 11 1132
甜味超标
甜味超标 2020-11-28 04:40

I am trying to convert a am/pm format time to a 24 hour format time

6:35 PM to 18:35

I tried this piece of code on playground but it doesnt

11条回答
  •  误落风尘
    2020-11-28 05:37

    Here is code for other way around

    For Swift 3

     func amAppend(str:String) -> String{
        var temp = str
        var strArr = str.characters.split{$0 == ":"}.map(String.init)
        var hour = Int(strArr[0])!
        var min = Int(strArr[1])!
        if(hour > 12){
            temp = temp + "PM"
        }
        else{
            temp = temp + "AM"
        }
        return temp
    }
    

提交回复
热议问题