public static int Weekday(DateTime dt, DayOfWeek startOfWeek)
{
return (dt.DayOfWeek - startOfWeek + 7) % 7;
}
This can be called using:
DateTime dt = DateTime.Now;
Console.WriteLine(Weekday(dt, DayOfWeek.Friday));
The above outputs:
4
as Tuesday is 4 days after Friday.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…