我在时间Span类别中有一个小问题,在那里,时间Span可以划分23:59,但不是24。
当然,客户希望进入24小时,以显示当天的结束,而不是23:59或00:00,即:00:00,即当天的开始。
目前,我的法典规定最终时间为:
if ( !TimeSpan.TryParse( ( gvr.FindControl( "txtTimeOff" ) as TextBox ).Text, out tsTimeOff ) )
{
this.ShowValidationError( String.Format( "Please enter a valid Time Off on row {0} .", gvr.RowIndex + 1 ) );
return false;
}
围绕这种情况的最佳工作是什么?
EDIT: (Solution 1)
if ( ( gvr.FindControl( "txtTimeOff" ) as TextBox ).Text == "24:00" )
{
tsTimeOff = new TimeSpan( 24, 0, 0 );
}
else
{
if ( !TimeSpan.TryParse( ( gvr.FindControl( "txtTimeOff" ) as TextBox ).Text, out tsTimeOff ) )
{
this.ShowValidationError(
String.Format( "Please enter a valid Time Off on row {0} .", gvr.RowIndex + 1 ) );
return false;
}
}
EDIT: (solution2)
string timeOff = ( gvr.FindControl( "txtTimeOff" ) as TextBox ).Text;
if ( !TimeSpan.TryParse(
timeOff == "24:00" ? "1.00:00:00" : timeOff
, out tsTimeOff ) )
{
this.ShowValidationError(
String.Format( "Please enter a valid Time Off on row {0} .", gvr.RowIndex + 1 ) );
return false;
}