从下午到上午如何计算两次? [英] how to calculate between two times from pm to am ?

查看:78
本文介绍了从下午到上午如何计算两次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要计算两次从 pm到am

i做了这段代码,但我从下午到上午遇到问题,因为这是另一天,

i need to calculate between two times from pm to am
i did this code but i face problem from pm to am because it's another day,

                        DateTime date1 = System.Convert.ToDateTime(DTimeBeginWork.Value);	
			DateTime date2 = System.Convert.ToDateTime(DTimeEndWork.Value);	
			TimeSpan ts = new TimeSpan();
			ts = date2.Subtract(date1);
			
//			DgNHours.DigitText = ((int)(ts.Hours)).ToString();
			DgNHours.DigitText = (ts.Hours.ToString());
			DgNMinutes.DigitText = (ts.Minutes.ToString());







谢谢u




thank u

推荐答案

只要您使用DataTime就可以了 - 所以我猜你的DTimeBeginWork只包含某种格式的时间而不是日期?



在这种情况下,如果结束时间值小于Beginwork时间值,您需要指定日期或假设日期是第二天...



例如



As long as you are working with DataTime you should be OK - so I guess your DTimeBeginWork contains only the time in some format and not the date?

That being the case, you either need to specify the date or assume the date is the next day if the endwork time value is less than the Beginwork time value...

e.g.

if (DTimeBeginWork.Value > DTimeEndWork.Value)
{
    date2.AddDays(1);
}


嗨!



TimeSpan t = date1 - date2;



你可以通过与类型相同的属性将结果翻译成小时,分钟,秒,日,月,年。
Hi !

TimeSpan t = date1 - date2;

with t you can translate result to Hour, Minute, Seccond, day, month, year through properties same as type.


这篇关于从下午到上午如何计算两次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆