减去两个日期 [英] Subtracting two dates

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

问题描述

我有两个日历和返回各自从calendar.SelectedDate日期时间。

I have two calendars and each return a DateTime from calendar.SelectedDate.

我如何去了解彼此减去两个选择的日期,给我量这两个选择之间的日子吗?

How do I go about subtracting the two selected dates from each other, giving me the amount of days between the two selections?

有一个calendar.Subtract(),但它需要一个时间跨度,而不是日期时间。

There is a calendar.Subtract() but it needs a TimeSpan instead of DateTime.

推荐答案

您可以使用 someDateTime.Subtract(otherDateTime),这个返回时间跨度具有 TotalDays 属性。

You can use someDateTime.Subtract(otherDateTime), this returns a TimeSpan which has a TotalDays property.

这篇关于减去两个日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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