mirror of
https://github.com/rafi1212122/BLHX.Server.git
synced 2025-12-12 14:34:39 +01:00
15 lines
453 B
C#
15 lines
453 B
C#
namespace BLHX.Server.Common.Utils
|
|
{
|
|
public static class DateTimeExtensions
|
|
{
|
|
public static int GetWeekOfMonth(this DateTime date)
|
|
{
|
|
int dayOfMonth = date.Day;
|
|
DateTime firstDayOfMonth = new(date.Year, date.Month, 1);
|
|
DayOfWeek firstDayOfWeek = firstDayOfMonth.DayOfWeek;
|
|
int offset = (dayOfMonth + (int)firstDayOfWeek - 1) / 7;
|
|
return offset + 1;
|
|
}
|
|
}
|
|
}
|