반응형
Notice
Recent Posts
Recent Comments
Link
«   2025/04   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
Tags
more
Archives
Today
Total
관리 메뉴

개발꿈나무

[C#] 특정 날짜의 주 가져오기 (GetWeekOfYear) 본문

C#/C#

[C#] 특정 날짜의 주 가져오기 (GetWeekOfYear)

HYOKYE0NG 2022. 1. 19. 10:53
반응형

특정 날짜의 주를 가져오는 코드는 다음과 같다.

CultureInfo myCI = new CultureInfo("en-US");
Calendar myCal = myCI.Calendar;
CalendarWeekRule myCWR = myCI.DateTimeFormat.CalendarWeekRule;
DayOfWeek myFirstDOW = myCI.DateTimeFormat.FirstDayOfWeek;

var week = myCI.GetWeekOfYear(DateTime.Now, myCWR, myFirstDOW);
 

Calendar.GetWeekOfYear(DateTime, CalendarWeekRule, DayOfWeek) 메서드 (System.Globalization)

지정된 DateTime 값의 날짜가 포함된 주(연도 기준)를 반환합니다.Returns the week of the year that includes the date in the specified DateTime value.

docs.microsoft.com

 

 

CalendarWeekRule

해당 연도의 첫째 주를 확인하기 위해 다양한 규칙을 정의한다.

 

  • FirstDay: 해당 연도의 첫째 주가 해당 연도의 첫 날에 시작해서 다음 주의 시작 요일 전에 끝나도록 지정
  • FirstFourDayWeek: 해당 주의 시작 요일 전까지 4일 이상이 있는 첫째 주가 해당 연도의 첫 째 주가 되도록 지정
  • FirstFullWeek: 해당 연도의 첫째 주를 해당 연도의 첫번째 시작요일에서 시작되도록 지정
CalendarWeekRule myCWR = CalendarWeekRule.FirstFullWeek;
 

CalendarWeekRule 열거형 (System.Globalization)

해당 연도의 첫째 주를 확인하기 위한 다양한 규칙을 정의합니다.Defines different rules for determining the first week of the year.

docs.microsoft.com

 

 

DayOfWeek

시작요일을 지정하는 속성으로 원하는 요일을 지정할 수 있다.

DayOfWeek myFirstDOW = DayOfWeek.Sunday;
 

DayOfWeek 열거형 (System)

요일을 지정합니다.Specifies the day of the week.

docs.microsoft.com

반응형
Comments