本文介绍了如何增加一天的额外时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友我有这个问题

hello frens i have this problem

DateTime arrtime = DateTime.Parse(txtarrivaltime.Text);
DateTime endTime = DateTime.Now;

TimeSpan span1 = endTime.Subtract(arrtime);
TimeSpan span2 = span1.Duration();

string NumOfDays = span1.Days;


string Shours = span2.Hours.ToString()+ ?;


现在我要动态增加小时数,即24 *一些值,例如24 * 1或24 * 2或...如果NumOfDays大于0,则以小时为单位.
请提供代码


now i want to dynamically add hours i.e. 24* some value like 24*1 or 24*2 or ... in Shours if the NumOfDays is more than 0. how can i do this dynamically?
please provide with the code

推荐答案

// add 1 day to the current date time
DateTime dt = DateTime.Now.AddDays(1);


DateTime arrtime = DateTime.Parse("txtarrivaltime.Text");
DateTime endTime = DateTime.Now;

TimeSpan span1 = endTime.Subtract(arrtime);
TimeSpan span2 = span1.Duration();

int NumOfDays = span1.Days;

TimeSpan span3 = new TimeSpan(24 * NumOfDays, 0, 0);
TimeSpan span4 = span2.Add(span3);
string Shours = span4.TotalHours.ToString();

(这是故意散布的,因此您可以更好地看到步骤)

(This is deliberately spread out, so you can see the steps better)



这篇关于如何增加一天的额外时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 00:26