How to get time (hour, minute, second) in Swift 3 using NSDate?

前端 未结 10 2575
孤独总比滥情好
孤独总比滥情好 2020-11-28 05:16

How can you determine the hour, minute and second from NSDate class in Swift 3?

In Swift 2:

let date = NSDate()
let calendar = NSCalendar.currentCale         


        
10条回答
  •  离开以前
    2020-11-28 06:01

    Swift 4

        let calendar = Calendar.current
        let time=calendar.dateComponents([.hour,.minute,.second], from: Date())
        print("\(time.hour!):\(time.minute!):\(time.second!)")
    

提交回复
热议问题