Home > AI > Language > Swift >

get current time

func getCurrentTime() -> String {
        let hour = Calendar.current.component(.hour, from: Date())

        switch hour {
            case 6..<12 :
                return NSLocalizedString("早上", comment: "早上")
            case 12 :
                return NSLocalizedString("中午", comment: "中午")
            case 13..<17 :
                return NSLocalizedString("下午", comment: "下午")
            case 17..<22 :
                return NSLocalizedString("晚上", comment: "晚上")
            default:
                return NSLocalizedString("午夜", comment: "午夜")
        }
    }

Leave a Reply