gpt4 book ai didi

objective-c - 在 Obj-c 中将秒转换为天、分钟和小时

转载 作者:太空狗 更新时间:2023-10-30 03:12:04 24 4
gpt4 key购买 nike

在 objective-c 中,如何将整数(代表秒)转换为天、分钟、小时?

谢谢!

最佳答案

在这种情况下,您只需要除法即可。

days = num_seconds / (60 * 60 * 24);
num_seconds -= days * (60 * 60 * 24);
hours = num_seconds / (60 * 60);
num_seconds -= hours * (60 * 60);
minutes = num_seconds / 60;

对于更复杂的日期计算,例如 1983 年 1 月 19 日下午 3 点后一千万秒内的天数,您可以将 NSCalendar 类与 NSDateComponents 一起使用。 Apple 的日期和时间编程指南可为您提供帮助。

关于objective-c - 在 Obj-c 中将秒转换为天、分钟和小时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/572049/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com