Adding Seconds to DateTime with a Valid Double Results in ArgumentOutOfRangeException

前端 未结 7 1238

The following code crashes and burns and I don\'t understand why:

DateTime dt = new DateTime(1970,1,1,0,0,0,0, DateTimeKind.Utc);
double d = double.Parse(\"1         


        
7条回答
  •  一向
    一向 (楼主)
    2021-01-17 10:42

    The value you are adding results in a date outside of the valid range of dates that a DateTime supports.

    DateTime supports 01/01/0001 00:00:00 to 31/12/9999 23:59:59.

    A simple calculation of 1332958778172/3600/24/365 gives 42267 years.

提交回复
热议问题