Created
October 27, 2018 14:11
-
-
Save marcos1262/34acf7f314af727eebb4c73f8bc64aff to your computer and use it in GitHub Desktop.
Abbreviated date interval String formatting
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
var timeString: String { | |
let formatter = DateComponentsFormatter() | |
formatter.allowedUnits = [.month, .day, .hour, .minute] | |
formatter.unitsStyle = .abbreviated | |
formatter.zeroFormattingBehavior = .dropAll | |
if let date = self.date, let interval = formatter.string(from: date, to: Date()) { | |
return "\(interval) ago" | |
} | |
return "unknown" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment