见过不少人、经过不少事、也吃过不少苦,感悟世事无常、人心多变,靠着回忆将往事串珠成链,聊聊感情、谈谈发展,我慢慢写、你一点一点看......
1、获取某日期所在周的第一天
public DateOnly GetFirstDayOfWeek(DateTime dateTime)
{
var culture = CultureInfo.CurrentCulture;
var differenceDays = dateTime.DayOfWeek - culture.DateTimeFormat.FirstDayOfWeek;
if (differenceDays < 0)
{
// 如果差值小于零,则将该差值加 7
differenceDays += 7;
}
// 给指定日期减去给定差值
dateTime = dateTime.AddDays(-differenceDays).Date