Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# asp.net中24小时时钟格式的日期时间_C#_Asp.net - Fatal编程技术网

C# asp.net中24小时时钟格式的日期时间

C# asp.net中24小时时钟格式的日期时间,c#,asp.net,C#,Asp.net,我已经为时间计算编写了此代码,但我的代码不接受24小时时间格式。它最多只能接受12点59分 这是我的代码: protected void TxtId_TextChanged(object sender, EventArgs e) { GridViewRow currentRow = (GridViewRow)((TextBox)sender).Parent.Parent; TextBox txtTakenDate = (TextBox)currentRow.FindContro

我已经为时间计算编写了此代码,但我的代码不接受24小时时间格式。它最多只能接受12点59分

这是我的代码:

protected void TxtId_TextChanged(object sender, EventArgs e)
{
    GridViewRow currentRow = (GridViewRow)((TextBox)sender).Parent.Parent;

    TextBox txtTakenDate = (TextBox)currentRow.FindControl("txtTakenDate");
    TextBox txtTakenTime = (TextBox)currentRow.FindControl("txtTakenTime");
    TextBox txtReturnedDate = (TextBox)currentRow.FindControl("txtReturndDate");
    TextBox txtReturnedTime = (TextBox)currentRow.FindControl("txtReturndTime");

    TextBox txtmttr = (TextBox)currentRow.FindControl("txtmttr");
    string StartDate = txtTakenDate.Text;
    string StartTime = txtTakenTime.Text;
    DateTime StartDateTime = DateTime.ParseExact((StartDate + " " + StartTime), "dd/MM/yyyy hh:mm", CultureInfo.InvariantCulture);

    string EndDate = Convert.ToString(txtReturnedDate.Text);
    string EndTime = Convert.ToString(txtReturnedTime.Text);
    DateTime EndDateTime = DateTime.ParseExact((EndDate + " " + EndTime), "dd/MM/yyyy hh:mm", CultureInfo.InvariantCulture);

    TimeSpan TotalTime = EndDateTime.Subtract(StartDateTime);
    txtmttr.Text = string.Format("{0}:{1}", (int)TotalTime.TotalHours, TotalTime.Minutes);
}

对24小时格式日期使用
HH
而不是
HH
,即
dd/MM/yyyy HH:MM

HH使用24小时制从00点到23点的时间

hh-使用12小时时钟从01点到12点的时间


检查

问题是,您使用的格式是“dd/MM/yyyyy hh:MM”,而不是“dd/MM/yyyy hh:MM”,持续数小时。

我认为应该有一条规则,即不要帮助那些急迫的人。。。有人有“非紧急”问题吗?@Noctis别以为有其他问题。没必要粗鲁。抱歉,顺便说一句,@SantanuMaulik并不是故意粗鲁,但最近我看到很多人在敦促别人帮助他们。。。这不是我希望在社区中看到的精神。。。在任何情况下,没有冒犯意味着,将来要更加体贴。