Skip to content

Instantly share code, notes, and snippets.

@bananafish911
Created October 15, 2016 09:21
Show Gist options
  • Save bananafish911/0c739f379443b87dd6db59274f652d07 to your computer and use it in GitHub Desktop.
Save bananafish911/0c739f379443b87dd6db59274f652d07 to your computer and use it in GitHub Desktop.
extension Date {
/// For application labels
func toStringAppFormatted() -> String {
let components = NSCalendar.current.dateComponents([Calendar.Component.day,
Calendar.Component.month,
Calendar.Component.year],
from: self)
return "\(components.day!).\(components.month!).\(components.year!)"
}
/// get local time
func toHoursMinutesString() -> String {
let components = NSCalendar.current.dateComponents([Calendar.Component.hour,
Calendar.Component.minute],
from: self)
return String(format: "%02d:%02d", components.hour!, components.minute!)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment