Skip to content

Instantly share code, notes, and snippets.

@nanotroy
Created June 5, 2019 21:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nanotroy/dadf94fb967c5fdb3510bbe673fc679c to your computer and use it in GitHub Desktop.
Save nanotroy/dadf94fb967c5fdb3510bbe673fc679c to your computer and use it in GitHub Desktop.
func countDownString(from date: Date, until nowDate: Date) -> String {
let calendar = Calendar(identifier: .gregorian)
let components = calendar
.dateComponents([.day, .hour, .minute, .second]
,from: nowDate,
to: date)
return String(format: "%02dd:%02dh:%02d:%02ds",
components.day ?? 00,
components.hour ?? 00,
components.minute ?? 00,
components.second ?? 00)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment