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
Convert integer to timespan
提问by Hyman Manson
How can I convert an int
to TimeSpan
?
如何将 an 转换int
为TimeSpan
?
example 486000000000
is int
as number of ticks. I want it to be represented as TimeSpan
示例486000000000
是int
刻度数。我希望它被表示为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 FromTicks
with
您可以替换FromTicks
为