Time.ToString("0.0")
显示为十进制“1.5”而不是 1:30。如何让它以时间格式显示?
private void xTripSeventyMilesRadioButton_CheckedChanged(object sender, EventArgs e)
{
//calculation for the estimated time label
Time = Miles / SeventyMph;
this.xTripEstimateLabel.Visible = true;
this.xTripEstimateLabel.Text = "Driving at this speed the estimated travel time in hours is: " + Time.ToString("0.0") + " hrs";
}
Time.ToString("hh:mm")
Formats:
HH:mm = 01:22
hh:mm tt = 01:22 AM
H:mm = 1:22
h:mm tt = 1:22 AM
HH:mm:ss = 01:22:45
EDIT:从现在开始我们知道时间是double
将代码更改为(假设您需要小时和分钟):
// This will handle over 24 hours
TimeSpan ts= System.TimeSpan.FromHours(Time);
string.Format("{0}:{1}", System.Math.Truncate(ts.TotalHours).ToString(), ts.Minutes.ToString());
or
// Keep in mind this could be bad if you go over 24 hours
DateTime.MinValue.AddHours(Time).ToString("H:mm");
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)