Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我以秒为单位存储时间,并希望以分钟和秒为单位显示它们,如“2m 6s”。理想情况下,这将通过本地化来完成。我怎样才能做到这一点?
这真的归结为标准数学。
如果您有秒数,只需将其除以 60 即可得到分钟数。对于剩余的秒数,只需将总秒数的模数乘以 60。
例如
int minutes = seconds / 60; int seconds = seconds % 60; NSString *formattedTime = [NSString stringWithFormat:@"%im %is", minutes, seconds];
其实很简单!