Skip to main content
added 10 characters in body
Source Link
iOS_Tejas
  • 269
  • 2
  • 9

Xcode 12.1. Swift 5

DateComponentsFormatter: A formatter that creates string representations, by using unitsStyle u can get a string as you want and mention allowedUnits. e

e.g: output for unitsStyle:: for 10000 secods

  1. full = "2 hours, 46 minutes, 49 seconds"
  2. positional = "2:46:40"
  3. abbreviated = "2h 46m 40s"
  4. spellOut = "two hours, forty-six minutes, forty seconds”
  5. short = "2hr,46 min,40 sec"
  6. brief = "2hr 46min 40sec"

Easy to use:

 let time = convertSecondsToHrMinuteSec(seconds: 10000) func convertSecondsToHrMinuteSec(seconds:Int) -> String{ let formatter = DateComponentsFormatter() formatter.allowedUnits = [.hour, .minute, .second] formatter.unitsStyle = .full let formattedString = formatter.string(from:TimeInterval(seconds))! print(formattedString) return formattedString } 

Xcode 12.1. Swift 5

DateComponentsFormatter: A formatter that creates string representations, by using unitsStyle u can get a string as you want and mention allowedUnits. e.g: output for unitsStyle:: for 10000 secods

  1. full = "2 hours, 46 minutes, 49 seconds"
  2. positional = "2:46:40"
  3. abbreviated = "2h 46m 40s"
  4. spellOut = "two hours, forty-six minutes, forty seconds”
  5. short = "2hr,46 min,40 sec"
  6. brief = "2hr 46min 40sec"

Easy to use:

 let time = convertSecondsToHrMinuteSec(seconds: 10000) func convertSecondsToHrMinuteSec(seconds:Int) -> String{ let formatter = DateComponentsFormatter() formatter.allowedUnits = [.hour, .minute, .second] formatter.unitsStyle = .full let formattedString = formatter.string(from:TimeInterval(seconds))! print(formattedString) return formattedString } 

Xcode 12.1. Swift 5

DateComponentsFormatter: A formatter that creates string representations, by using unitsStyle u can get a string as you want and mention allowedUnits.

e.g: output for unitsStyle:: for 10000 secods

  1. full = "2 hours, 46 minutes, 49 seconds"
  2. positional = "2:46:40"
  3. abbreviated = "2h 46m 40s"
  4. spellOut = "two hours, forty-six minutes, forty seconds”
  5. short = "2hr,46 min,40 sec"
  6. brief = "2hr 46min 40sec"

Easy to use:

 let time = convertSecondsToHrMinuteSec(seconds: 10000) func convertSecondsToHrMinuteSec(seconds:Int) -> String{ let formatter = DateComponentsFormatter() formatter.allowedUnits = [.hour, .minute, .second] formatter.unitsStyle = .full let formattedString = formatter.string(from:TimeInterval(seconds))! print(formattedString) return formattedString } 
added 27 characters in body
Source Link
iOS_Tejas
  • 269
  • 2
  • 9

Xcode 12.1. Swift 5

DateComponentsFormatter: A formatter that creates string representations, by using unitsStyle u can get a string as you want and mention allowedUnits. e.g: output for unitsStyle:: for 10000 secods

  1. full = "2 hours, 46 minutes, 49 seconds"
  2. positional = "2:46:40"
  3. abbreviated = "2h 46m 40s"
  4. spellOut = "two hours, forty-six minutes, forty seconds”
  5. short = "2hr,46 min,40 sec"
  6. brief = "2hr 46min 40sec"

Easy to use:

 let time = convertSecondsToHrMinuteSec(seconds: 10000) func convertSecondsToHrMinuteSec(seconds:Int) -> String{ let formatter = DateComponentsFormatter() formatter.allowedUnits = [.hour, .minute, .second] formatter.unitsStyle = .full let formattedString = formatter.string(from:TimeInterval(seconds))! print(formattedString) return formattedString } 

DateComponentsFormatter: A formatter that creates string representations, by using unitsStyle u can get a string as you want and mention allowedUnits. e.g: output for unitsStyle:: for 10000 secods

  1. full = "2 hours, 46 minutes, 49 seconds"
  2. positional = "2:46:40"
  3. abbreviated = "2h 46m 40s"
  4. spellOut = "two hours, forty-six minutes, forty seconds”
  5. short = "2hr,46 min,40 sec"
  6. brief = "2hr 46min 40sec"

Easy to use:

 let time = convertSecondsToHrMinuteSec(seconds: 10000) func convertSecondsToHrMinuteSec(seconds:Int) -> String{ let formatter = DateComponentsFormatter() formatter.allowedUnits = [.hour, .minute, .second] formatter.unitsStyle = .full let formattedString = formatter.string(from:TimeInterval(seconds))! print(formattedString) return formattedString } 

Xcode 12.1. Swift 5

DateComponentsFormatter: A formatter that creates string representations, by using unitsStyle u can get a string as you want and mention allowedUnits. e.g: output for unitsStyle:: for 10000 secods

  1. full = "2 hours, 46 minutes, 49 seconds"
  2. positional = "2:46:40"
  3. abbreviated = "2h 46m 40s"
  4. spellOut = "two hours, forty-six minutes, forty seconds”
  5. short = "2hr,46 min,40 sec"
  6. brief = "2hr 46min 40sec"

Easy to use:

 let time = convertSecondsToHrMinuteSec(seconds: 10000) func convertSecondsToHrMinuteSec(seconds:Int) -> String{ let formatter = DateComponentsFormatter() formatter.allowedUnits = [.hour, .minute, .second] formatter.unitsStyle = .full let formattedString = formatter.string(from:TimeInterval(seconds))! print(formattedString) return formattedString } 
Source Link
iOS_Tejas
  • 269
  • 2
  • 9

DateComponentsFormatter: A formatter that creates string representations, by using unitsStyle u can get a string as you want and mention allowedUnits. e.g: output for unitsStyle:: for 10000 secods

  1. full = "2 hours, 46 minutes, 49 seconds"
  2. positional = "2:46:40"
  3. abbreviated = "2h 46m 40s"
  4. spellOut = "two hours, forty-six minutes, forty seconds”
  5. short = "2hr,46 min,40 sec"
  6. brief = "2hr 46min 40sec"

Easy to use:

 let time = convertSecondsToHrMinuteSec(seconds: 10000) func convertSecondsToHrMinuteSec(seconds:Int) -> String{ let formatter = DateComponentsFormatter() formatter.allowedUnits = [.hour, .minute, .second] formatter.unitsStyle = .full let formattedString = formatter.string(from:TimeInterval(seconds))! print(formattedString) return formattedString }