How to get the current year, month and day in Swift

1 Answer

0 votes
import Foundation

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

let year = calendar.component(.year, from: today)
let month = calendar.component(.month, from: today)
let day = calendar.component(.day, from: today)

print(year)
print(month)
print(day)




/*
run:

2021
6
18

*/

 



answered Jun 18, 2021 by avibootz
...