How to Set a variable with current year in Swift?

Hello friends Today, through this tutorial, I will tell you how to Set a variable with current year in Swift. So let’s go.

let year = Calendar.current.component(.year, from: Date())

you can print date, month and year from this code. 

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)