gpt4 book ai didi

c# - TimeSpan 只显示小时数?

转载 作者:行者123 更新时间:2023-11-30 23:32:56 39 4
gpt4 key购买 nike

我的 MVC 应用程序中有这个问题。

我有 TimeSpan,其中包含例如 2 天 15 小时 31 分 34 秒。

我只想显示小时/分钟/秒,问题是我想将天数添加到小时,如 63:31:34 。我尝试添加一个新的时间跨度喜欢time.Add(new TimeSpan(time.Days * 24, 0, 0),但 .NET 添加了 2 天。

你能帮我解决我的问题吗?

最佳答案

添加到 Jeppes 注释中,避免 double 的方法可能是积极使用天数:

TimeSpan interval = new TimeSpan(1, 15, 42, 45, 750); 
Console.WriteLine("{0}:{1}:{2}", interval.Days * 24 + interval.Hours, interval.Minutes, interval.Seconds);

// result: 39:42:45

关于c# - TimeSpan 只显示小时数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34109315/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com