How to get the current hour, minute and second in Swift

1 Answer

0 votes
import Foundation

let today = Date()
let calendar = Calendar.current

let hour = calendar.component(.hour, from: today)
let minute = calendar.component(.minute, from: today)
let second = calendar.component(.second, from: today)

print(hour)
print(minute)
print(second)




/*
run:

9
41
32

*/

 



answered Jun 18, 2021 by avibootz
...