xxxxxxxxxx
// get the current date and time
let currentDateTime = Date()
// get the user's calendar
let userCalendar = Calendar.current
// choose which date and time components are needed
let requestedComponents: Set<Calendar.Component> = [
.year,
.month,
.day,
.hour,
.minute,
.second
]
// get the components
let dateTimeComponents = userCalendar.dateComponents(requestedComponents, from: currentDateTime)
// now the components are available
dateTimeComponents.year // 2016
dateTimeComponents.month // 10
dateTimeComponents.day // 8
dateTimeComponents.hour // 22
dateTimeComponents.minute // 42
dateTimeComponents.second // 17