Adding Seconds to DateTime with a Valid Double Results in ArgumentOutOfRangeException

前端 未结 7 1235

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:58

    DateTime dt = new DateTime(1970,1,1,0,0,0,0, DateTimeKind.Utc);    
    Console.Write(dt.AddSeconds(1332958778172D));
    

    Except that...

    1332958778172/60/60/24/365 = 42,267 years... which DateTime can only go up to 23:59:59.9999999, December 31, 9999

提交回复
热议问题