最有效的方法,计算两个日期时间之间的周数 [英] Most efficient way to count number of weeks between two datetimes

查看:543
本文介绍了最有效的方法,计算两个日期时间之间的周数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正是因为它在锡说,我只需要在C#计数周两个日期之间(即7天的跨度,而不是日历周)的最有效的方式。

Exactly as it says on the tin, I just need the most efficient way of counting weeks (i.e. 7-day spans, not calendar weeks) between two dates in C#.

推荐答案

7获得天鸿沟的数量。

Get the number of days and divide by 7.

int weeks = (date1 - date2).TotalDays / 7;

您可能有长达6天余,将不包括在周数

You may well have a remainder of up to 6 days that will not be included in the number of weeks.

这篇关于最有效的方法,计算两个日期时间之间的周数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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