如何获取指定周的星期日日期?
示例,如果我的日期时间包含“11/19/2020”的日期,我怎样才能获得11/19周的星期日?该值为11/13。
答案 0 :(得分:2)
这是您所需要的
DateTime d = new DateTime(2020,11,19);
int diff = d.DayOfWeek - DayOfWeek.Sunday;
DateTime lastSunday = d.AddDays(-diff);
Console.WriteLine(lastSunday);
答案 1 :(得分:0)
new DateTime(2020,11,19).AddDays(-(new DateTime(2020,11,19).DayOfWeek - DayOfWeek.Sunday))