C# - 两个日期之间的差异? [英] C# - Difference between two dates?

查看:107
本文介绍了C# - 两个日期之间的差异?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图计算两个日期之间的差异。这是我目前使用的:

  INT currentyear = DateTime.Now.Year; 

现在的DateTime = DateTime.Now;
的DateTime然后=新日期时间(currentyear,12,26);
时间跨度差异=现在 - 那么,
INT天= diff.Days;
label1.Text = days.ToString()+天,直到圣诞节;



除了它是一天一切工作正常。我假定这是因为它不指望任何小于一个完整的24小时。有没有办法得到它这样做呢?谢谢你。


解决方案

  INT天数=(int)的Math.Ceiling(diff.TotalDays ); 


I am trying to calculate the difference between two dates. This is what I'm currently using:

int currentyear = DateTime.Now.Year;

DateTime now = DateTime.Now;
DateTime then = new DateTime(currentyear, 12, 26);
TimeSpan diff = now - then;
int days = diff.Days;
label1.Text = days.ToString() + " Days Until Christmas";

All works fine except it is a day off. I am assuming this is because it does not count anything less than 24 hours a complete day. Is there a way to get it to do so? Thank you.

解决方案

int days = (int)Math.Ceiling(diff.TotalDays);

这篇关于C# - 两个日期之间的差异?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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