What am I doing wrong with allowsFractionalUnits on NSDateComponentsFormatter?

前端 未结 3 1562
孤独总比滥情好
孤独总比滥情好 2020-12-28 13:30

Basically what I want is to get the value of a time interval represented in hours only, without rounding it to full hours (using NSDateComponentsFormatter to get it properly

3条回答
  •  借酒劲吻你
    2020-12-28 13:56

    Looking at the documentation, it’s using a lot of interesting language (emphasis mine):

    Fractional units may be used when a value cannot be exactly represented using the available units. For example, if minutes are not allowed, the value “1h 30m” could be formatted as “1.5h”.

    While to me it seems that it would only make sense for the values in the documentation to be values that actually work, it’s certainly possible that there is some combination of time value, formatter options, and calendar/locale settings that would make this work. Definitely worth filing a Radar on both the functionality and the documentation.

提交回复
热议问题