From the course: C# and .NET Essential Training

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Using the DateTime class

Using the DateTime class - C# Tutorial

From the course: C# and .NET Essential Training

Using the DateTime class

- Now that we've learned a little bit about working with numbers dotnet, let's turn our attention to dates and times. The date time class is the basic data type for working with dates and times. And since it is one of the default name spaces, I don't need to do anything to include it in my program. So let's open up the sample code in the date time class folder. And like I said, I can start working with it, I don't have to do anything special to include it because it's one of the implicit using statements that gets created for me. So to get the current date and time, we can access the now static property of the date time class. So I can create a variable name now, and I'll just set it to date time .now, and let's go ahead and print that out. If you're only interested in the date and you don't care about the time you can use the today property. And this just gets you the date with the time component set to midnight. So…

Contents