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

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

    swift 4
    
    ==> Getting iOS device current time:-
    
    print(" ---> ",(Calendar.current.component(.hour, from: Date())),":",
                   (Calendar.current.component(.minute, from: Date())),":",
                   (Calendar.current.component(.second, from: Date())))
    
    output: ---> 10 : 11: 34
    

提交回复
热议问题