DateTime.Today Proprietà
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Ottiene la data corrente.
public:
static property DateTime Today { DateTime get(); };
public static DateTime Today { get; }
static member Today : DateTime
Public Shared ReadOnly Property Today As DateTime
Oggetto che è impostato sulla data corrente, con il componente ora impostato su 00.00.00.
Nell'esempio seguente viene usata la Date proprietà per recuperare la data corrente. Illustra anche come è possibile formattare un DateTime valore usando alcune delle stringhe di formato data e ora standard. Si noti che l'output prodotto dalla terza chiamata al ToString(String) metodo usa l'identificatore di formato g per includere il componente time, ovvero zero.
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 example displays output similar to the following:
// 5/3/2012 12:00:00 AM
//
// 5/3/2012
// Thursday, May 03, 2012
// 5/3/2012 12:00 AM
open System
// Get the current date.
let thisDay = DateTime.Today
// Display the date in the default (general) format.
printfn $"{thisDay}\n"
// Display the date in a variety of formats.
printfn $"{thisDay:d}"
printfn $"{thisDay:D}"
printfn $"{thisDay:g}"
// The example displays output similar to the following:
// 5/3/2012 12:00:00 AM
//
// 5/3/2012
// Thursday, May 03, 2012
// 5/3/2012 12:00 AM
Module modMain
Public Sub Main()
' Get the current date.
Dim thisDay As DateTime = 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"))
End Sub
End Module
' The example displays output similar to the following:
' 5/3/2012 12:00:00 AM
'
' 5/3/2012
' Thursday, May 03, 2012
' 5/3/2012 12:00 AM
A partire da .NET Framework versione 2.0, il valore restituito è un DateTime oggetto la cui Kind proprietà restituisce Local.
Poiché restituisce la data corrente senza l'ora corrente, la Today proprietà è adatta per l'uso nelle applicazioni che funzionano solo con date. Per informazioni dettagliate, vedere Scelta tra DateTime, DateTimeOffset, TimeSpan e TimeZoneInfo. Al contrario, la TimeOfDay proprietà restituisce l'ora corrente senza la data corrente e la Now proprietà restituisce sia la data corrente che l'ora corrente.
Prodotto | Versioni |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1 |
UWP | 10.0 |
Feedback su .NET
.NET è un progetto open source. Seleziona un collegamento per fornire feedback: