计算天数 [英] Calculating the count of days

查看:92
本文介绍了计算天数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,请帮我提供示例代码,我可以使用该示例代码查找任意两个数据字符串之间的天数.例如我怎么知道2009年1月12日到2010年5月11日之间的天数.

谢谢

Hi there, please help me with Sample code i can use to find the count of days between any two data strings. e.g. How acan i know the number of days between 1/12/2009 and 5/11/2010.

Thanks

推荐答案

代码如下-
Code as follows -
DateTime oldDate = new DateTime(2002,7,15);<br />
DateTime newDate = DateTime.Now;<br />
// Difference in days, hours, and minutes.<br />
TimeSpan ts = newDate - oldDate;<br />
// Difference in days.<br />
int differenceInDays = ts.Days;<br />
Console.WriteLine("Difference in days: {0} ", differenceInDays);





MSDN链接此处 [





MSDN link here[^].


使用此代码:

Use this Code :

DateTime dt1 = new DateTime(2009, 12, 1);
DateTime dt2 = new DateTime(2010, 11, 5);
int nodays = dt2.Subtract(dt1).Days;



nodays 将保留这些日期之间的天数.

干杯.
:rose:



The nodays will hold the number of days between those dates.

Cheers.
:rose:


这篇关于计算天数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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