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);
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)