"TimeSpan.Seconds" 值在 1 分 1 秒时使用 TimeSpan.Pase("h:mm:ss") 重置为“1”
"TimeSpan.Seconds" Value Resets to "1" At 1 Minute 1 Second Using TimeSpan.Pase("h:mm:ss")
我正在使用以下代码来测试我遇到的这个问题-
Console.WriteLine(x);
TimeSpan ts = TimeSpan.Parse(x);
y = ts.Seconds;
Console.WriteLine(y);
1 分钟后该代码 returns 以下 -
0:01:01
1
"x" 的值是一个时间戳,格式如下 - "h:mm:ss"。
有谁知道为什么在 1 分 1 秒时 y == 1,而不是 y == 61?
您需要使用 ts.TotalSeconds
而不是 ts.Seconds
。
ts.TotalSeconds
returns 整个时间跨度内经过的秒数,而 ts.Seconds
returns 只是秒数。
在你的情况下,你会期望 ts.Minutes = 1
、ts.Seconds = 1
和 ts.TotalSeconds = 61.0
。
我正在使用以下代码来测试我遇到的这个问题-
Console.WriteLine(x);
TimeSpan ts = TimeSpan.Parse(x);
y = ts.Seconds;
Console.WriteLine(y);
1 分钟后该代码 returns 以下 -
0:01:01
1
"x" 的值是一个时间戳,格式如下 - "h:mm:ss"。
有谁知道为什么在 1 分 1 秒时 y == 1,而不是 y == 61?
您需要使用 ts.TotalSeconds
而不是 ts.Seconds
。
ts.TotalSeconds
returns 整个时间跨度内经过的秒数,而 ts.Seconds
returns 只是秒数。
在你的情况下,你会期望 ts.Minutes = 1
、ts.Seconds = 1
和 ts.TotalSeconds = 61.0
。