【发布时间】:2019-04-23 17:57:32
【问题描述】:
我正在尝试以“[分钟]:[秒]”的格式格式化 TimeSpan 元素。在这种格式中,2 分 8 秒看起来像“02:08”。我已经尝试了使用 String.Format 和 ToString 方法的各种选项,但我得到了一个 FormatException。这是我目前正在尝试的:
DateTime startTime = DateTime.Now;
// Do Stuff
TimeSpan duration = DateTime.Now.Subtract(startTime);
Console.WriteLine("[paragraph of information] Total Duration: " + duration.ToString("mm:ss"));
我做错了什么?如何使用我想要的格式格式化 TimeSpan 元素?
【问题讨论】:
标签: c#