Datetime in C# - Date and Time in C# - C# DateTime Examples
Datetime in C#
- In C# we used the Date Time when there is a need to work with the dates and times.
- We can format the date and time in different formats by the properties and methods of the Date Time.
- The value of the Date Time is between the 12:00:00 midnight, January 1 0001 and 11:59:59 PM, December 31, 9999 A.D.
- We have different ways to create the Date Time object and it has Time, Date, Culture, Localization, Milliseconds.
From Date Time create the Date and Time
From String creation of Date Time
Empty Date Time
Date Time from Ticks
Localization with Date Time
Date Time with date, time and milliseconds
Properties of Date Time in C#
- We can get the name of the day from the week with the help of the Day Of Week property.
- We will use Day Of Year property, to get the day of the year and we use Time Of Day property, to get time in a Date Time.
- Today property will return the object of the Date Time, which is having today's value and the value of time is 12:00:00. Now property will return the Date Time object, which is having the current date and time.
- The Utc property of Date Time will return the Coordinated Universal Time (UTC).
- The Kind property returns value where the representation of time is done by the instance, which is based on the local time, Coordinated Universal Time (UTC) and it also shows the unspecified default value.
We will show it with the code with the pattern in a table
|"f"||Full date time. Short time.|
|"F"||Full date time. Long Time.|
|"g"||Generate date time. Long Time.|
|"G"||General date time. Long Time.|
|"O","o"||Round trip date/time.|
|"s"||Sortable date time.|
|"u"||Universal sortable date time.|
|"U"||Universal full date-time.|