Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DateTime.AddDays vs Calendar.AddDays

What is the difference between DateTime.AddDays and Calendar.AddDays?
Is DateTime type calendar independent?

like image 985
Jarlaxle Avatar asked Dec 04 '22 09:12

Jarlaxle


1 Answers

DateTime.AddDays just converts days to ticks and adds this number of ticks to the date time. The default implementation of Calendar.AddDays does exactly the same. However, since it is a virtual method it can be implemented in specific calendar in a more complicated way, e.g. something like here: http://codeblog.jonskeet.uk/2010/12/01/the-joys-of-date-time-arithmetic/

like image 60
Konstantin Oznobihin Avatar answered Dec 22 '22 09:12

Konstantin Oznobihin