What am I doing wrong with allowsFractionalUnits on NSDateComponentsFormatter?

前端 未结 3 1538
孤独总比滥情好
孤独总比滥情好 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:42

    According to Open Radar #32024200:

    After doing some digging (disassembling Foundation), it looks like every call to -[_unitFormatter stringFromNumber:] in -[NSDateComponentsFormatter _stringFromDateComponents:] is passed an +[NSNumber numberWithInteger:] which drops floating point data.

    You're not doing anything wrong. The flag is simply broken.

提交回复
热议问题