DateTimeOffset.Date DateTimeOffset.Date DateTimeOffset.Date DateTimeOffset.Date Property

定義

取得、 DateTime 、現在の日付部分を表す値DateTimeOffsetオブジェクト。Gets a DateTime value that represents the date component of the current DateTimeOffset object.

public:
 property DateTime Date { DateTime get(); };
public DateTime Date { get; }
member this.Date : DateTime
Public ReadOnly Property Date As DateTime

プロパティ値

A DateTime 、現在の日付部分を表す値DateTimeOffsetオブジェクト。A DateTime value that represents the date component of the current DateTimeOffset object.

次の例の値を取得、Date特定の日付のプロパティ。The following example retrieves the value of the Date property for a specific date. 一部の標準およびカスタムの日付のみの書式指定子を使用してコンソールにその値が表示されます。It then displays that value to the console using some standard and custom date-only format specifiers.

// Illustrate Date property and date formatting
DateTimeOffset thisDate = new DateTimeOffset(2008, 3, 17, 1, 32, 0, new TimeSpan(-5, 0, 0));
string fmt;                      // format specifier

// Display date only using "D" format specifier
// For en-us culture, displays:
//   'D' format specifier: Monday, March 17, 2008
fmt = "D";
Console.WriteLine("'{0}' format specifier: {1}",  
                  fmt, thisDate.Date.ToString(fmt));

// Display date only using "d" format specifier
// For en-us culture, displays:
//   'd' format specifier: 3/17/2008
fmt = "d";
Console.WriteLine("'{0}' format specifier: {1}",  
                  fmt, thisDate.Date.ToString(fmt));

// Display date only using "Y" (or "y") format specifier
// For en-us culture, displays:
//   'Y' format specifier: March, 2008
fmt = "Y";
Console.WriteLine("'{0}' format specifier: {1}",  
                  fmt, thisDate.Date.ToString(fmt));
                  
// Display date only using custom format specifier
// For en-us culture, displays:
//   'dd MMM yyyy' format specifier: 17 Mar 2008
fmt = "dd MMM yyyy";
Console.WriteLine("'{0}' format specifier: {1}",  
                  fmt, thisDate.Date.ToString(fmt));
' Illustrate Date property and date formatting
Dim thisDate As New DateTimeOffset(#3/17/2008 1:32AM#, New TimeSpan(-5, 0, 0))
Dim fmt As String                    ' format specifier
' Display date only using "D" format specifier
' For en-us culture, displays:
'   'D' format specifier: Monday, March 17, 2008
fmt = "D"
Console.WriteLine("'{0}' format specifier: {1}", _ 
                  fmt, thisDate.Date.ToString(fmt))

' Display date only using "d" format specifier
' For en-us culture, displays:
'   'd' format specifier: 3/17/2008
fmt = "d"
Console.WriteLine("'{0}' format specifier: {1}", _ 
                  fmt, thisDate.Date.ToString(fmt))

' Display date only using "Y" (or "y") format specifier
' For en-us culture, displays:
'   'Y' format specifier: March, 2008
fmt = "Y"
Console.WriteLine("'{0}' format specifier: {1}", _ 
                  fmt, thisDate.Date.ToString(fmt))
                  
' Display date only using custom format specifier
' For en-us culture, displays:
'   'dd MMM yyyy' format specifier: 17 Mar 2008
fmt = "dd MMM yyyy"
Console.WriteLine("'{0}' format specifier: {1}", _ 
                  fmt, thisDate.Date.ToString(fmt))

注釈

このプロパティから、時刻部分の重要な一部の削除、DateTimeOffsetオブジェクトし、その重要な日付部分のみを返します。This property removes any significant part of the time component from a DateTimeOffset object and returns only its significant date component. たとえば場合、DateTimeOffsetオブジェクトは、日付と時刻の値を持つ"1/12/07 午後 4 時 01 + 7:30"、プロパティを返します、DateTimeの値"1/12/07 12時 00分: 00 AM"。For example, if the DateTimeOffset object has a date and time value of "1/12/07 4:01pm +7:30", the property returns a DateTime value of "1/12/07 12:00:00 AM". DateTime値は日付のみを表示する標準またはカスタム書式指定子のいずれかを使用して、表示されます。The DateTime value can then be displayed by using any of the standard or custom format specifiers that display dates only. (図の例のセクションを参照してください)。(See the Example section for an illustration.)

値、 DateTime.Kind 、返されたプロパティDateTimeオブジェクトは常にDateTimeKind.Unspecifiedします。The value of the DateTime.Kind property of the returned DateTime object is always DateTimeKind.Unspecified. 値は影響されません、Offsetプロパティ。It is not affected by the value of the Offset property.

その時刻部分なしの日付を表示するのには、"D"も使用できますか、"d"書式指定子。例については、例を参照してください。To display a date without its time component, you can also use the "D" or "d" format specifiers; for an illustration, see the Example section.

適用対象

こちらもご覧ください