我能够将分钟转换为小时和分钟。例如35 分钟转换为 0:35,65 分钟转换为 1:5。
但我希望它在前面两个示例中分别以 00:35 和 01:05 的格式显示。这里有什么建议吗?
我试过下面的代码
TimeSpan ts = TimeSpan.FromMinutes(intMins);
Console.WriteLine(string.Format("{0}:{1}", ts.Hours, ts.Minutes ) );
最佳答案
使用字符串格式00
:
Console.WriteLine(string.Format("{0:00}:{1:00}", ts.Hours, ts.Minutes));
或查看以下 SO 帖子以格式化 TimeSpan
对象:
关于c# - 如何在 C# 中将小时从 h 转换为 hh,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22765285/