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

前端 未结 10 2585
孤独总比滥情好
孤独总比滥情好 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

    let date = Date()       
    let units: Set = [.hour, .day, .month, .year]
    let comps = Calendar.current.dateComponents(units, from: date)
    

提交回复
热议问题