【发布时间】:2014-02-18 15:50:26
【问题描述】:
我想将双精度转换为日期时间。
这不是从 Excel 转换而来的。我有一个 double 表示秒,只是希望它表示为以分钟和秒为单位的时间。
121.0005 = 2:01 分钟
【问题讨论】:
-
DateTime不是这个意思。
我想将双精度转换为日期时间。
这不是从 Excel 转换而来的。我有一个 double 表示秒,只是希望它表示为以分钟和秒为单位的时间。
121.0005 = 2:01 分钟
【问题讨论】:
DateTime 不是这个意思。
使用TimeSpan:
double seconds = 121.0005;
TimeSpan sp = TimeSpan.FromSeconds(seconds);
Console.Write(string.Format("{0} mins", sp.ToString(@"m\:ss")));
【讨论】:
您需要的是TimeSpan,而不是DateTime,因为您的输入代表一个时间值,而不是Date。
使用TimeSpan.FromSeconds 方法。
double sec = 121.0005;
TimeSpan ts = TimeSpan.FromSeconds(sec);
【讨论】: