C# 将整数转换为时间跨度

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15584709/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 17:17:39  来源:igfitidea点击:

Convert integer to timespan

c#

提问by Hyman Manson

How can I convert an intto TimeSpan?

如何将 an 转换intTimeSpan

example 486000000000is intas number of ticks. I want it to be represented as TimeSpan

示例486000000000int刻度数。我希望它被表示为TimeSpan

回答by coolmine

You can use the From methods, those will allow you to convert days/hours/minutes/seconds/milliseconds/ticks to TimeSpam format as follows:

您可以使用 From 方法,这些方法将允许您将天/小时/分钟/秒/毫秒/滴答转换为 TimeSpam 格式,如下所示:

TimeSpan ts = TimeSpan.FromTicks(486000000000);
Console.WriteLine(ts.ToString());

You can replace FromTickswith

您可以替换FromTicks