DateTimeOffset.Year プロパティ
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
現在の DateTimeOffset オブジェクトで表される日付の年要素を取得します。
public:
property int Year { int get(); };
public int Year { get; }
member this.Year : int
Public ReadOnly Property Year As Integer
現在の DateTimeOffset オブジェクトの 0 ~ 9999 の整数値で表される年要素。
次の例では、4 つの異なる方法で値の DateTimeOffset 年のコンポーネントを表示します。
プロパティの Year 値を取得します。
"y" 書式指定子を使用して メソッドを呼び出 ToString(String) すこと。
"yy" 書式指定子を使用して メソッドを呼び出 ToString(String) すこと。
"yyyy" 書式指定子を使用して メソッドを呼び出 ToString(String) すこと。
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.
let theTime = DateTimeOffset(2008, 2, 17, 9, 0, 0, DateTimeOffset.Now.Offset)
printfn $"The year component of {theTime} is {theTime.Year}."
printfn $"""The year component of {theTime} is{theTime.ToString " y"}."""
printfn $"The year component of {theTime} is {theTime:yy}."
printfn $"The year component of {theTime} is {theTime: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 受けません。
また、"y"、"yy"、または "yyyy" カスタム書式指定子を使用して メソッドを呼び出ToStringすことで、オブジェクトの年コンポーネントの文字列表現DateTimeOffsetを作成することもできます。
製品 | バージョン |
---|---|
.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 | 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 |
.NET に関するフィードバック
.NET はオープンソース プロジェクトです。 フィードバックを提供するにはリンクを選択します。