블로그 이미지
Every unexpected event is a path to learning for you.

카테고리

분류 전체보기 (2737)
Unity3D (817)
Programming (474)
Server (33)
Unreal (4)
Gamebryo (56)
Tip & Tech (228)
협업 (58)
3DS Max (3)
Game (12)
Utility (136)
Etc (96)
Link (32)
Portfolio (19)
Subject (90)
iOS,OSX (53)
Android (14)
Linux (5)
잉여 프로젝트 (2)
게임이야기 (3)
Memories (20)
Interest (38)
Thinking (38)
한글 (30)
PaperCraft (5)
Animation (408)
Wallpaper (2)
재테크 (18)
Exercise (3)
나만의 맛집 (3)
냥이 (10)
육아 (16)
Total
Today
Yesterday
04-27 14:56

[에러 로그]

[Exception] ArgumentOutOfRangeException: Year, Month, and Day parameters describe 
            an un-representable DateTime.

----

 

개발을 하면서 연도와 상관없이 날짜(월/일/시/분/초) 비교를 위해 임의로 현재 날짜를 9999년으로 변환하게 해놨는데..

하필 오늘이 2024년 2월 29일 윤일(閏日)이다.

 

2024년 2월 29일에서 연도만 9999년으로 바꾸면서 new DateTime()을 하려니 위 에러가 발생했다.

잘 돌아가나 했던 로직이 윤일(閏日)에 에러가 남..(잘못만든거..)

 

해당 월(Month)에 해당 일(Day)이 있는지 체크하는 함수가 있으니 아래와 같이 체크해보고 처리하던가,

if (DateTime.DaysInMonth(2024,2) == 29)
    dt = new DateTime(2024, 2, 29);

 

아니면 다른 방식으로 처리를 해야 될 것 같다.

 

나의 경우는 연도를 같게 만들고 나머지를 비교하기 위해 무조건 9999년(임의 연도)으로 만들었는데..

에러가 나서 반대로 비교할 DateTime이 9999년이면 현재 연도(DateTime.Now.Year)에 맞추게 변경했다.

 

각자 원하는 방식으로 예외처리를 하면 될 것 같다.

 

[참조] https://stackoverflow.com/questions/11246563/year-month-and-day-parameters-describe-an-un-representable-datetime-exception

 

Year, Month, and Day parameters describe an un-representable DateTime Exception

I'm adding an object to a list within an ASP.NET MVC 3 application using the following code but one of the properties of the object is giving me difficulties. ls.Add(new UserRoleModel { UserRoleId...

stackoverflow.com

 

 

 

반응형
Posted by blueasa
, |