How to modify formatted string with 'positional' option by using swift's DateComponentsFormatter

278 Views Asked by At

I want to get a relatively formatted string from TimeInterval. So I have tried following code to get custom formatted string:

let ft = DateComponentsFormatter()
ft.unitsStyle = .positional
ft.zeroFormattingBehavior = .dropAll
// TimeInterval can be either 5400 or 3600 or 1800 as well
let formattedString = ft.string(from: TimeInterval(1800))

But I can't format my string like this: "1:30h" and if i have only hour "1h" or i have only minutes "30m"

0

There are 0 best solutions below