Skip to content

Instantly share code, notes, and snippets.

@fewlinesofcode
Created February 20, 2020 17:41
Show Gist options
  • Save fewlinesofcode/35dfa96d9ce543669051b19ce37fa1c2 to your computer and use it in GitHub Desktop.
Save fewlinesofcode/35dfa96d9ce543669051b19ce37fa1c2 to your computer and use it in GitHub Desktop.
Human readable Date to String
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