Reputation: 569
I'm trying to find a way to use Swift's DateComponentsFormatter
with multiple unitsStyle
properties, depending on the actual component.
For example, I'd like to use .abbreviated
for the day property and .brief
for others, creating strings such as: 1d 9hr 22min
. If I used .brief
for all components, I'd get 1day 9hr 22min
. If I used .abbreviated
, I'd get 1d 9h 22m
.
It looks like the combination I want isn't possible, because unitsStyle
is a property of the formatter. But does anyone know if I can make a more complex configuration? Or am I going to have to create multiple DateComponentsFormatter
s?
(I want to use DateComponentsFormatter
to get the localisation of the time units. So any alternative formatters would also need to support localisation out of the box, rather than having localised formatting strings.)
Upvotes: 0
Views: 284