在日期中花费时间........................... [英] Making Time in the date.....................

查看:69
本文介绍了在日期中花费时间...........................的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我有6个数字

日嘴年

例如..

5/5/2005
2/6/2008

ok i have 6 numbers

day mouth year

eg..

5/5/2005
2/6/2008

using those numbers how can i find how many days there are in-between them?

推荐答案

尝试:
DateTime date1 = new DateTime(2005, 5, 5);
DateTime date2 = new DateTime (2006, 6, 2);
TimeSpan diff = date1 - date2;
int daysBetween = diff.Days;
Console.WriteLine(daysBetween);


您可以从另一个时间点中减去一个时间点,因为为时间结构System.DataTime定义了减法运算符和运算符-". -"运算符的返回类型为结构System.TimeSpan.它具有实例属性System.TimeSpan.TotalDays.

这就是您所需要的.

请参阅: http://msdn.microsoft.com/en-us/library/system.datetime. aspx [^ ], http://msdn.microsoft.com/en-us/library/system.timespan. aspx [^ ].

—SA
You can subtract one point in time from another one, because subtraction operation and operator "-" is defined for the time structure System.DataTime. The return type of the "-" operator is the structure System.TimeSpan. It has an instance property System.TimeSpan.TotalDays.

That''s all you need.

See: http://msdn.microsoft.com/en-us/library/system.datetime.aspx[^], http://msdn.microsoft.com/en-us/library/system.timespan.aspx[^].

—SA


尝试一下.
Try this.
DateTime d1 = new DateTime(2005, 5, 5);
DateTime d2 = new DateTime(2008, 6, 5);
TimeSpan ts = d2 - d1;
int days = ts.Days;


这篇关于在日期中花费时间...........................的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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