我有一个我想展示的计时器minutes:seconds:hundreds of seconds。由于 C# 时间跨度没有获得数百但只有毫秒的方法,因此我需要以某种方式对其进行格式化。
TimeSpan ts = stopWatch.Elapsed;
currentTime = String.Format("{0:00}:{1:00}:{2:00}", ts.Minutes, ts.Seconds, Math.Round(Convert.ToDecimal(ts.Milliseconds),2));
ClockTextBlock.Text = currentTime;
Run Code Online (Sandbox Code Playgroud)
我试过了Math.Round,什么也没发生。结果仍然是 1-3 位数字,如下所示:
01:12:7
01:12:77
01:12:777
Run Code Online (Sandbox Code Playgroud)
我希望格式总是像
01:12:07
01:12:77
Run Code Online (Sandbox Code Playgroud)