Tracks
/
C#
C#
/
Syllabus
/
Datetimes
Da

Datetimes in C#

3 exercises

About Datetimes

A DateTime in C# is an immutable object that contains both date and time information. The date and time information can be accessed through its built-in properties.

Manipulating a DateTime can be done by calling one of its methods. As DateTime values can never change after having been defined, all methods that appear to modify a DateTime will actually return a new DateTime.

Comparing DateTime instances can be done using the default comparison operators (<, >, etc.). The current date (and time) can be retrieved through the DateTime.Now property.

An important aspect of dates in C# is that they are culture-dependent. As such, any DateTime method that deals with strings will be dependent on the current culture. This includes the DateTime.Parse() method that parses a string to a DateTime, as well as the DateTime class' ToString() method that converts a DateTime to a string.

Edit via GitHub The link opens in a new window or tab

Learn Datetimes

Practicing is locked

Unlock 2 more exercises to practice Datetimes