Get current date in Swift 3? [closed] Get current date in Swift 3? [closed] swift swift

Get current date in Swift 3? [closed]


You say in a comment you want to get "15.09.2016".

For this, use Date and DateFormatter:

let date = Date()let formatter = DateFormatter()

Give the format you want to the formatter:

formatter.dateFormat = "dd.MM.yyyy"

Get the result string:

let result = formatter.string(from: date)

Set your label:

label.text = result

Result:

15.09.2016


You can do it in this way with Swift 3.0:

let date = Date()let calendar = Calendar.currentlet components = calendar.dateComponents([.year, .month, .day], from: date)let year =  components.yearlet month = components.monthlet day = components.dayprint(year)print(month)print(day)