Date time in C#

ยท 1 min read

It is quite common to see Date and Time used in the game, here are some frequently used methods:

Get the current date time

// Get the current date and time
DateTime currentDateTime= DateTime.Now;

Get date and time difference between two dates

// Get time difference between two date
DateTime oldDateTime = new DateTime(2020,1,1);
DateTime newDateTime= DateTime.Now;

TimeSpan ts = newDateTime - oldDateTime;

int diffDays = ts.Days;