How can I set the variable year
to the current year in Swift?
let year = ...
Use Calendar
and Date
:
let year = Calendar.current.component(.year, from: Date())
let date = Date() let calendar = Calendar.current let year = calendar.component(.year, from: date) let month = calendar.component(.month, from: date) let day = calendar.component(.day, from: date)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With