Dates
A date can be represented in C# using the DateTime
value type. It is a struct with two static properties called MinValue
, which is January 1, 0001 00:00:00, and MaxValue
, which is December 31, 9999 11:59:59 P.M. As the names suggest, both these values represent the minimum and maximum dates according to the Gregorian calendar date format. The default value for DateTime
objects is MinValue
.
It is possible to construct a DateTime
variable in various ways. Some of the most common ways are as follows:
- Assigning the current time as follows:
var now = DateTime.Now;
This sets the variable to the current date and time on the calling computer, expressed as the local time.
var now = DateTime.UtcNow;
This sets the variable to the current date and time on this computer, expressed as the Coordinated Universal Time (UTC).
- You can also use constructors for passing days, months, years, hours, minutes, and even seconds and milliseconds.
- There is also a special...