Set a variable with current year in Swift
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)