स्विफ्ट 4.2 और 5
let date = Date()
var calendar = Calendar.current
print(calendar.dateComponents([.year, .month, .day, .hour, .minute], from: date))
calendar.timeZone = TimeZone(identifier: "UTC")!
let components = calendar.dateComponents([.hour, .year, .minute], from: date)
print("All Components : \(components)")
let hour = calendar.component(.hour, from: date)
let minutes = calendar.component(.minute, from: date)
let seconds = calendar.component(.second, from: date)
print("\(hour):\(minutes):\(seconds)")
स्विफ्ट 3.0
let date = Date()
var calendar = NSCalendar.current
print(calendar.dateComponents([.year, .month, .day, .hour, .minute], from: date as Date))
let unitFlags = Set<Calendar.Component>([.hour, .year, .minute])
calendar.timeZone = TimeZone(identifier: "UTC")!
let components = calendar.dateComponents(unitFlags, from: date)
print("All Components : \(components)")
let hour = calendar.component(.hour, from: date)
let minutes = calendar.component(.minute, from: date)
let seconds = calendar.component(.second, from: date)
print("\(hour):\(minutes):\(seconds)")