C# DateTime: Complete Guide
In C#, DateTime is a struct that is used to represent date and time. It contains many properties and methods that can be used to retrieve and manipulate information about dates and times, such as getting the year, month, day, hour, minute, second, and so on. Here are some commonly used methods and properties of DateTime.
- Now: obtain the current date and time
- Today: Get the current date with a time part of 00:00:00.
- Extract the date part, with the time part being 00:00:00.
- DayOfYear: Get the day number within the current year.
- AddDays, AddMonths, AddYears: Increase the specified number of days, months, or years.
- Obtain the day of the week.
- ToString: converting date and time to a string
- Parse、TryParse: Convert a string to a DateTime object
In addition to the methods and properties mentioned above, the DateTime structure also offers many other methods and properties that can be chosen based on specific needs. DateTime is a widely used type that is frequently encountered in C# development.