Last active
March 24, 2017 11:19
-
-
Save eleev/1ba837e50687a96b5e941d5ad6fd0518 to your computer and use it in GitHub Desktop.
Extension for Date class that provides easy-to-use feature for convering date to string. Swift 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Date { | |
struct Formatter { | |
static let shortDate = DateFormatter(dateStyle: .short) | |
static let longDate = DateFormatter(dateStyle: .long) | |
static let fullDate = DateFormatter(dateStyle: .full) | |
} | |
var shortDate: String { return Formatter.shortDate.string(from: self) } | |
var longDate: String { return Formatter.longDate.string(from: self) } | |
var fullDate: String { return Formatter.fullDate.string(from: self) } | |
var mediumTime: String { | |
let dateFormatter = DateFormatter() | |
dateFormatter.dateFormat = "HH:mm" | |
dateFormatter.locale = Locale.current | |
return dateFormatter.string(from: self) | |
} | |
var longTime: String { | |
let dateFormatter = DateFormatter() | |
dateFormatter.dateFormat = "HH:mm:ss" | |
dateFormatter.locale = Locale.current | |
return dateFormatter.string(from: self) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment