Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想从今天开始计算特定日期的剩余天数。如何计算C#中2个日期之间的差异??
(注意:这个答案是在问题措辞非常不同时写的)
假设您的日期是DateTime或DateTimeOffset:
DateTime
DateTimeOffset
TimeSpan delta = date1 - date2
TimeSpan GetDelta(DateTime d1, DateTime d2) { return (d1 - d2).TotalDays; }