Поделиться через


DateTime.Today Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets the current date.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

Syntax

'Declaration
Public Shared ReadOnly Property Today As DateTime
public static DateTime Today { get; }

Property Value

Type: System.DateTime
An object set to today's date, with the time component set to 00:00:00.

Remarks

The return value is a DateTime whose Kind property returns Local.

Because it returns the current date without the current time, the Today property is suitable for use in applications that work with dates only. In contrast, the TimeOfDay property returns the current time without the current date, and the Now property returns both the current date and the current time.

Examples

The following example uses the Date property to retrieve the current date. It also illustrates how a DateTime value can be formatted using some of the standard date and time format strings. Note that the output produced by the third call to the ToString(String) method uses the g format specifier to include the time component, which is zero.

' Get current date.
Dim thisDay As DateTime = DateTime.Today
' Display the date in a variety of formats.
outputBlock.Text += thisDay.ToString("d") & vbCrLf
outputBlock.Text += thisDay.ToString("D") & vbCrLf
outputBlock.Text += thisDay.ToString("g") & vbCrLf
// Get current date.
DateTime thisDay = DateTime.Today;
// Display the date in a variety of formats.
outputBlock.Text += thisDay.ToString("d") + "\n";
outputBlock.Text += thisDay.ToString("D") + "\n";
outputBlock.Text += thisDay.ToString("g") + "\n";

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.