我怎样才能得到本周开始的日期?我如何找到一周的开始(星期日和星期一)只知道现在的时间C#?类似于:DateTime.Now.StartWeek(Monday);
3 回答
翻过高山走不出你
TA贡献1875条经验 获得超3个赞
public static class DateTimeExtensions{ public static DateTime StartOfWeek(this DateTime dt, DayOfWeek startOfWeek) { int diff = (7 + (dt.DayOfWeek - startOfWeek)) % 7; return dt.AddDays(-1 * diff).Date; }}
DateTime dt = DateTime.Now.StartOfWeek(DayOfWeek.Monday); DateTime dt = DateTime.Now.StartOfWeek(DayOfWeek.Sunday);
- 3 回答
- 0 关注
- 381 浏览
添加回答
举报
0/150
提交
取消