Skip to main content

I have buildbuilt a mashup from theof existing answers to simplify everything and have as fewreduce the amount of code as possibleneeded for Swift 3.

func hmsFrom(seconds: Int, completion: @escaping (_ hours: Int, _ minutes: Int, _ seconds: Int)->()) { completion(seconds / 3600, (seconds % 3600) / 60, (seconds % 3600) % 60) } func getStringFrom(seconds: Int) -> String { return seconds < 10 ? "0\(seconds)" : "\(seconds)" } 

Usage:

var seconds: Int = 100 hmsFrom(seconds: seconds) { hours, minutes, seconds in let hours = getStringFrom(seconds: hours) let minutes = getStringFrom(seconds: minutes) let seconds = getStringFrom(seconds: seconds) print("\(hours):\(minutes):\(seconds)") } 

Prints:

00:01:40

I have build a mashup from the existing answers to simplify everything and have as few code as possible for Swift 3.

func hmsFrom(seconds: Int, completion: @escaping (_ hours: Int, _ minutes: Int, _ seconds: Int)->()) { completion(seconds / 3600, (seconds % 3600) / 60, (seconds % 3600) % 60) } func getStringFrom(seconds: Int) -> String { return seconds < 10 ? "0\(seconds)" : "\(seconds)" } 

Usage:

var seconds: Int = 100 hmsFrom(seconds: seconds) { hours, minutes, seconds in let hours = getStringFrom(seconds: hours) let minutes = getStringFrom(seconds: minutes) let seconds = getStringFrom(seconds: seconds) print("\(hours):\(minutes):\(seconds)") } 

Prints:

00:01:40

I have built a mashup of existing answers to simplify everything and reduce the amount of code needed for Swift 3.

func hmsFrom(seconds: Int, completion: @escaping (_ hours: Int, _ minutes: Int, _ seconds: Int)->()) { completion(seconds / 3600, (seconds % 3600) / 60, (seconds % 3600) % 60) } func getStringFrom(seconds: Int) -> String { return seconds < 10 ? "0\(seconds)" : "\(seconds)" } 

Usage:

var seconds: Int = 100 hmsFrom(seconds: seconds) { hours, minutes, seconds in let hours = getStringFrom(seconds: hours) let minutes = getStringFrom(seconds: minutes) let seconds = getStringFrom(seconds: seconds) print("\(hours):\(minutes):\(seconds)") } 

Prints:

00:01:40

I have build a mashup from the existing answers to simplify everything and have as few code as possible for Swift 3.

func hmsFrom(seconds: Int, completion: @escaping (_ hours: Int, _ minutes: Int, _ seconds: Int)->()) { completion(seconds / 3600, (seconds % 3600) / 60, (seconds % 3600) % 60) } func getStringFrom(seconds: Int) -> String { return sseconds < 10 ? "0\(sseconds)" : "\(sseconds)"   } 

Usage:

var seconds: Int = 100 hmsFrom(seconds: seconds) { hours, minutes, seconds in let hours = getStringFrom(seconds: hours) let minutes = getStringFrom(seconds: minutes) let seconds = getStringFrom(seconds: seconds) print("\(hours):\(minutes):\(seconds)") } 

Prints:

00:01:40

I have build a mashup from the existing answers to simplify everything and have as few code as possible for Swift 3.

func hmsFrom(seconds: Int, completion: @escaping (_ hours: Int, _ minutes: Int, _ seconds: Int)->()) { completion(seconds / 3600, (seconds % 3600) / 60, (seconds % 3600) % 60) } func getStringFrom(seconds: Int) -> String { return s < 10 ? "0\(s)" : "\(s)"   } 

Usage:

var seconds: Int = 100 hmsFrom(seconds: seconds) { hours, minutes, seconds in let hours = getStringFrom(seconds: hours) let minutes = getStringFrom(seconds: minutes) let seconds = getStringFrom(seconds: seconds) print("\(hours):\(minutes):\(seconds)") } 

Prints:

00:01:40

I have build a mashup from the existing answers to simplify everything and have as few code as possible for Swift 3.

func hmsFrom(seconds: Int, completion: @escaping (_ hours: Int, _ minutes: Int, _ seconds: Int)->()) { completion(seconds / 3600, (seconds % 3600) / 60, (seconds % 3600) % 60) } func getStringFrom(seconds: Int) -> String { return seconds < 10 ? "0\(seconds)" : "\(seconds)" } 

Usage:

var seconds: Int = 100 hmsFrom(seconds: seconds) { hours, minutes, seconds in let hours = getStringFrom(seconds: hours) let minutes = getStringFrom(seconds: minutes) let seconds = getStringFrom(seconds: seconds) print("\(hours):\(minutes):\(seconds)") } 

Prints:

00:01:40

added 32 characters in body
Source Link
David Seek
  • 17.2k
  • 19
  • 110
  • 138

I have build a mashup from the existing answers to simplify everything and have as few code as possible for Swift 3.

func hmsFrom(seconds: Int, completion: @escaping (_ hours: Int, _ minutes: Int, _ seconds: Int)->()) { completion(seconds / 3600, (seconds % 3600) / 60, (seconds % 3600) % 60) } func getStringFrom(seconds: Int) -> String { return s < 10 ? "0\(s)" : "\(s)" } 

Usage:

var seconds: Int = 100 hmsFrom(seconds: seconds) { hhours, mminutes, sseconds in let hours = getStringFrom(seconds: hhours) let minutes = getStringFrom(seconds: mminutes) let seconds = getStringFrom(seconds: sseconds) print("\(hours):\(minutes):\(seconds)") } 

Prints:

00:01:40

I have build a mashup from the existing answers to simplify everything and have as few code as possible for Swift 3.

func hmsFrom(seconds: Int, completion: @escaping (_ hours: Int, _ minutes: Int, _ seconds: Int)->()) { completion(seconds / 3600, (seconds % 3600) / 60, (seconds % 3600) % 60) } func getStringFrom(seconds: Int) -> String { return s < 10 ? "0\(s)" : "\(s)" } 

Usage:

var seconds: Int = 100 hmsFrom(seconds: seconds) { h, m, s in let hours = getStringFrom(seconds: h) let minutes = getStringFrom(seconds: m) let seconds = getStringFrom(seconds: s) print("\(hours):\(minutes):\(seconds)") } 

Prints:

00:01:40

I have build a mashup from the existing answers to simplify everything and have as few code as possible for Swift 3.

func hmsFrom(seconds: Int, completion: @escaping (_ hours: Int, _ minutes: Int, _ seconds: Int)->()) { completion(seconds / 3600, (seconds % 3600) / 60, (seconds % 3600) % 60) } func getStringFrom(seconds: Int) -> String { return s < 10 ? "0\(s)" : "\(s)" } 

Usage:

var seconds: Int = 100 hmsFrom(seconds: seconds) { hours, minutes, seconds in let hours = getStringFrom(seconds: hours) let minutes = getStringFrom(seconds: minutes) let seconds = getStringFrom(seconds: seconds) print("\(hours):\(minutes):\(seconds)") } 

Prints:

00:01:40

added 40 characters in body
Source Link
David Seek
  • 17.2k
  • 19
  • 110
  • 138
Loading
added 2 characters in body
Source Link
David Seek
  • 17.2k
  • 19
  • 110
  • 138
Loading
Source Link
David Seek
  • 17.2k
  • 19
  • 110
  • 138
Loading