好吧,这是我在 StackOverflow 上的第一个问题,我看到评论不是很好(在我有机会修复它之前,帖子一直被删除)。给我一个机会!我的理解是问题应该尽可能直接而不是引起“讨论”?
这是我已经尝试过的,但输出不是我所期望的
int secondsToHours(seconds) {
int totalSec = seconds;
int hrs = totalSec % 3600;
int secs = totalSec % 60;
int mins = totalSec / 60;
string result = hrs + ":" + mins + ":" + secs;
Console.WriteLine(result);
Console.ReadLine();
}
请您参考如下方法:
您可以使用 TimeSpan 结构:
TimeSpan ts = TimeSpan.FromSeconds(seconds);
然后构建你想要的字符串:
ts.ToString(@"hh\:mm\:ss")
