Smart Formatting of time span

前端 未结 3 2025
抹茶落季
抹茶落季 2021-02-04 16:40

I need a method to format a NSTimeInterval (time span in seconds) into a string to produce something like \"about 10 minutes ago\", \"1h, 20min\",

3条回答
  •  野的像风
    2021-02-04 16:58

    You might want to refer to Facebook three20 framework. In their NSDateAdditions, they provided a few pretty formats for date. It might be better than you extend it.

    Refer to the source at https://github.com/facebook/three20/blob/master/src/Three20Core/Sources/NSDateAdditions.m

    - (NSString*)formatShortRelativeTime; will give you "<1m", "50m", "3h", "3d"

提交回复
热议问题