C# DateTime Today
Description
DateTime Today
gets the current date.
Syntax
DateTime.Today
has the following syntax.
public static DateTime Today { get; }
Example
The following example uses the Date property to retrieve the current date.
It illustrates how a DateTime value can be formatted using some of the standard date and time format strings.
//from ww w. j a va2 s . c o m
using System;
public class Example
{
public static void Main()
{
// Get the current date.
DateTime thisDay = DateTime.Today;
// Display the date in the default (general) format.
Console.WriteLine(thisDay.ToString());
Console.WriteLine();
// Display the date in a variety of formats.
Console.WriteLine(thisDay.ToString("d"));
Console.WriteLine(thisDay.ToString("D"));
Console.WriteLine(thisDay.ToString("g"));
}
}
The code above generates the following result.