下面的代碼有效。最後一行將代碼格式化爲dd:hh:mm。我怎樣才能把它顯示爲hh:mm。如果我將最後一行更改爲Convert Timespan - Gridview
e.Row.Cells[4].Text = timeSpent.ToString(@"hh\:mm");
我在24小時內收到一個異常。其目的是讓輸出26:30,而不是1時02分30秒
我的代碼是:
TimeSpan timeSpent = TimeSpan.Zero;
protected void GridViewFortNight_RowDataBound(object sender, GridViewRowEventArgs e)
{
var tempTimeCalc = "";
if (e.Row.RowType == DataControlRowType.DataRow)
{
tempTimeCalc = e.Row.Cells[4].Text.ToString();
timeSpent += TimeSpan.Parse(tempTimeCalc);
}
else if (e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[4].Text = timeSpent.ToString(@"dd\:hh\:mm");
}
}
既然你想通過24小時,我會猜測你正在試圖積累自從和事件或類似事件以來已經過去的時間。你能告訴我你想要達到什麼嗎?你爲什麼需要超過24小時? – Agustin0987