DateTimeOffset.Year DateTimeOffset.Year DateTimeOffset.Year DateTimeOffset.Year Property

定義

現在で表される日付の年要素を取得DateTimeOffsetオブジェクト。Gets the year component of the date represented by the current DateTimeOffset object.

public:
 property int Year { int get(); };
public int Year { get; }
member this.Year : int
Public ReadOnly Property Year As Integer

プロパティ値

現在の年コンポーネントDateTimeOffsetオブジェクトの 0 ~ 9999 の整数値として表されます。The year component of the current DateTimeOffset object, expressed as an integer value between 0 and 9999.

次の例の表示の年の部分をDateTimeOffset4 つの方法で値。The following example displays the year component of a DateTimeOffset value in four different ways:

  • 値を取得することによって、Yearプロパティ。By retrieving the value of the Year property.

  • 呼び出すことによって、 ToString(String) "y"書式指定子を持つメソッド。By calling the ToString(String) method with the "y" format specifier.

  • 呼び出すことによって、 ToString(String) "yy"書式指定子を持つメソッド。By calling the ToString(String) method with the "yy" format specifier.

  • 呼び出すことによって、 ToString(String) "yyyy"書式指定子を持つメソッド。By calling the ToString(String) method with the "yyyy" format specifier.

DateTimeOffset theTime = new DateTimeOffset(2008, 2, 17, 9, 0, 0, 
                             DateTimeOffset.Now.Offset);
Console.WriteLine("The year component of {0} is {1}.", 
                  theTime, theTime.Year);

Console.WriteLine("The year component of {0} is{1}.", 
                  theTime, theTime.ToString(" y"));

Console.WriteLine("The year component of {0} is {1}.", 
                  theTime, theTime.ToString("yy"));
                  
Console.WriteLine("The year component of {0} is {1}.", 
                  theTime, theTime.ToString("yyyy"));
// The example produces the following output:
//    The year component of 2/17/2008 9:00:00 AM -07:00 is 2008.
//    The year component of 2/17/2008 9:00:00 AM -07:00 is 8.
//    The year component of 2/17/2008 9:00:00 AM -07:00 is 08.
//    The year component of 2/17/2008 9:00:00 AM -07:00 is 2008.
Dim theTime As New DateTimeOffset(#2/17/2008 9:00AM#, _
                                  DateTimeOffset.Now.Offset)
Console.WriteLine("The year component of {0} is {1}.", _
                  theTime, theTime.Year)

Console.WriteLine("The year component of {0} is{1}.", _
                  theTime, theTime.ToString(" y"))

Console.WriteLine("The year component of {0} is {1}.", _
                  theTime, theTime.ToString("yy"))
                  
Console.WriteLine("The year component of {0} is {1}.", _
                  theTime, theTime.ToString("yyyy"))
' The example produces the following output:
'    The year component of 2/17/2008 9:00:00 AM -07:00 is 2008.
'    The year component of 2/17/2008 9:00:00 AM -07:00 is 8.
'    The year component of 2/17/2008 9:00:00 AM -07:00 is 08.
'    The year component of 2/17/2008 9:00:00 AM -07:00 is 2008.

注釈

Yearプロパティがの値によって影響を受けません、Offsetプロパティ。The Year property is not affected by the value of the Offset property.

文字列表現を作成することも、DateTimeOffset呼び出すことによってオブジェクトの年の部分、 ToString "y"、"yy"または"yyyy"カスタム書式指定子を持つメソッド。You can also create a string representation of a DateTimeOffset object's year component by calling the ToString method with the "y", "yy", or "yyyy" custom format specifiers.

適用対象