【问题标题】:How to convert between time units in .NET? [closed]如何在 .NET 中的时间单位之间进行转换? [关闭]
【发布时间】:2012-11-03 18:45:51
【问题描述】:

哪些.NET 函数允许在时间单位之间进行转换?

例如:如果我有一个 Integer,我知道它代表以分钟为单位的持续时间,那么在 .NET 中将该数字转换为毫秒的最佳方法是什么?

Dim durationInMinutes as Integer = 10
Dim durationInMilliseconds As Integer = <???>(10);  // what is the function to use here?

【问题讨论】:

  • @MitchWheat 我确定你的意思是minutes * 60 * 1000,你只是在测试人,对吧? ;)
  • 是的!我必须以某种方式获得娱乐! ....... ;)
  • @MitchWheat:这不是证明内置函数更好用吗?

标签: .net datetime time integer


【解决方案1】:
int minutes = 5;
int milliseconds = TimeSpan.FromMinutes(minutes).TotalMilliseconds;

【讨论】:

  • TotalMilliseconds 属性实际上返回一个双精度 - 不要忘记强制转换它!
猜你喜欢
  • 1970-01-01
  • 2010-09-12
  • 1970-01-01
  • 2011-10-28
  • 2015-10-05
  • 2019-06-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多