Created
February 20, 2020 17:41
-
-
Save fewlinesofcode/35dfa96d9ce543669051b19ce37fa1c2 to your computer and use it in GitHub Desktop.
Human readable Date to String
This file contains hidden or 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
let dcf = DateComponentsFormatter() | |
dcf.unitsStyle = .abbreviated | |
dcf.includesApproximationPhrase = false | |
dcf.includesTimeRemainingPhrase = true | |
dcf.allowedUnits = [.day, .hour, .minute, .second] | |
let past = Date().advanced(by: -10) | |
let now = Date() | |
let humanReadableString = dcf.string(from: past, to: now) | |
print(humanReadableString!) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment