本文介绍了如何计算C#中的剩余天数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 如何计算剩余时间 我的迟到条目详细信息分钟栏详情 Late Mints详情 处理日期分钟 2014年3月3日30 2014年3月4日15 2014年3月5日15 2014年3月6日15 2014年3月30日30 2014年3月8日15 2014年3月10日15 2014年3月11日30 2014年3月12日15 以上网格查看分钟详情扣除许可人剩余180分钟 Permissionhrs为180; int remainingday = 0 ; total1 = permissionhrs; foreach (GridViewRow gvRows in gvLatemints.Rows) { total1 = Convert.ToInt32(total1) - Convert.ToInt32(gvRows.Cells [ 2 ]。Text.Trim()); lblError.Text = 总休假: + total1; if (total1 < = 0 ) { remainingday = Convert.ToInt32(gvLatemints.Rows.Count) - remainingday; // Response.Write(剩余天数:+剩余日期); lbldeductleave.Text = 剩余天数: +剩余天数; return ; } 剩余日++; } 最后我想剩余日计数结果是6 解决方案 Ok 。我想我现在明白你了。你的问题是剩余日变量。当你的总数达到0时你没有增加它,所以你没有计算那一天。解决方案很简单,像这样修改你的代码(注意粗线): int remainingday = 0 ; total1 = permissionhrs; foreach (GridViewRow gvRows in gvLatemints.Rows) { total1 = Convert.ToInt32(total1) - Convert.ToInt32(gvRows.Cells [ 2 ]。Text.Trim()); lblError.Text = 总休假: + total1; if (total1 < = 0 ) { 剩余日++; remainingday = Convert.ToInt32(gvLatemints.Rows.Count) - 剩余日; // Response.Write(剩余天数:+剩余日期); lbldeductleave.Text = 剩余天数: +剩余天数; return ; } 剩余日++; } 编辑 如果事实,我认为这是一个更清晰的代码: int remainingday = 0 ; total1 = permissionhrs; foreach (GridViewRow gvRows in gvLatemints.Rows) { total1 = Convert.ToInt32(total1) - Convert.ToInt32(gvRows.Cells [ 2 ]。Text.Trim()); 剩余日++; lblError.Text =& quot;总休假:& quot; + total1; if (total1& lt; = 0 ) { remainingday = Convert.ToInt32(gvLatemints.Rows.Count) - 剩余日; // Response.Write(& quot;剩余天数:& quot; +剩余天数); lbldeductleave.Text =& quot;剩余天数:& quot; +剩下的日子; return ; } } How to count remaining hoursMy Late entry Details in minutes Column DetailsLate Mints DetailsProcess Dateminutes03 Mar 20143004 Mar 20141505 Mar 20141506 Mar 20141507 Mar 20143008 Mar 20141510 Mar 20141511 Mar 20143012 Mar 201415The above Grid view minutes Details Deduct the permissionhrs 180 remaining minutesPermissionhrs is 180;int remainingday = 0;total1 = permissionhrs;foreach (GridViewRow gvRows in gvLatemints.Rows){ total1 = Convert.ToInt32(total1) - Convert.ToInt32(gvRows.Cells[2].Text.Trim()); lblError.Text = "Total Leave :" + total1; if (total1 <= 0) { remainingday = Convert.ToInt32(gvLatemints.Rows.Count) - remainingday; //Response.Write("remaining days : " + remainingday); lbldeductleave.Text = "remaining days : " + remainingday ; return; } remainingday++;} finally I want remainingday count result is 6 解决方案 Ok. I think i understand you now. Your problem is the remainingday variable. When your total reaches 0 you are not incrementing it,so you have not counted that day. The solution is easy,modify your code like this (notice the bold line):int remainingday = 0; total1 = permissionhrs; foreach (GridViewRow gvRows in gvLatemints.Rows) { total1 = Convert.ToInt32(total1) - Convert.ToInt32(gvRows.Cells[2].Text.Trim()); lblError.Text = "Total Leave :" + total1; if (total1 <= 0) { remainingday++; remainingday = Convert.ToInt32(gvLatemints.Rows.Count) - remainingday; //Response.Write("remaining days : " + remainingday); lbldeductleave.Text = "remaining days : " + remainingday ; return; } remainingday++; }EditIf fact,I think this is a clearer code:int remainingday = 0; total1 = permissionhrs; foreach (GridViewRow gvRows in gvLatemints.Rows) { total1 = Convert.ToInt32(total1) - Convert.ToInt32(gvRows.Cells[2].Text.Trim()); remainingday++; lblError.Text = &quot;Total Leave :&quot; + total1; if (total1 &lt;= 0) { remainingday = Convert.ToInt32(gvLatemints.Rows.Count) - remainingday; //Response.Write(&quot;remaining days : &quot; + remainingday); lbldeductleave.Text = &quot;remaining days : &quot; + remainingday ; return; } } 这篇关于如何计算C#中的剩余天数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-30 18:20
查看更多