将TimeSpan.TotalMilliseconds转换为日期时间,并将其格式设置为小时:分钟
问题描述:
我有点困惑日期时间转换
I kinda confuse about the date time conversion
在我定义的模型中
public DateTime? Sent { get; set; }
public DateTime? Reply { get; set; }
public double ResponseTime { get; set; }
我正在使用的linq部分
in linq part i am using
ResponseTime = (u.Reply - u.sent).TotalMilliseconds
未格式化并显示为979809803
我想知道如何将其转换为日期时间格式,并最终将格式显示为小时:分钟,例如发送日期和日期回复之间的2:45.
I want to know how do i convert it to datetime format, and eventually will display the format as hour:minute, for instance 2:45 between the date sent and date reply.
答
从DateTime中减去DateTime会产生一个TimeSpan.看看 TimeSpan.ToString方法(字符串),了解如何您可以自定义格式值.
Subtracting a DateTime from a DateTime yields a TimeSpan. Have a look at the TimeSpan.ToString Method (String) to see how you can custom format the value.
您可以将ResponseTime更改回TimeSpan,然后从此处更改为字符串.
You can change ResponseTime back to a TimeSpan and from there to a string.
TimeSpan ResponseTimeSpan = new TimeSpan(0, 0, 0, (int)ResponseTime);
string ResponseTimeDisplay = ResponseTimeSpan.ToString();