Skip to content

Instantly share code, notes, and snippets.

@jianghaoyuan2007
Last active May 4, 2017 03:31
Show Gist options
  • Save jianghaoyuan2007/82a3f01b5d99bad020e49b69091ba155 to your computer and use it in GitHub Desktop.
Save jianghaoyuan2007/82a3f01b5d99bad020e49b69091ba155 to your computer and use it in GitHub Desktop.
A Simple Date Component Example
import Foundation
let calendar = NSCalendar(calendarIdentifier: NSCalendar.Identifier.gregorian)
let units: NSCalendar.Unit = [.hour, .minute, .second]
let date = Date()
let dateComponents = calendar!.components(units, from: date)
print(dateComponents) // hour: 11 minute: 26 second: 33 isLeapMonth: false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment