DateTimeOffset.Second プロパティ

定義

現在の DateTimeOffset オブジェクトが表す時刻の秒要素を取得します。Gets the second component of the clock time represented by the current DateTimeOffset object.

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

プロパティ値

DateTimeOffset オブジェクトの 0 ~ 59 の整数値で表される秒要素。The second component of the DateTimeOffset object, expressed as an integer value between 0 and 59.

次の例では、DateTimeOffset オブジェクトの2番目のコンポーネントを3つの異なる方法で表示します。The following example displays the second component of a DateTimeOffset object in three different ways:

  • Second プロパティの値を取得する。By retrieving the value of the Second property.

  • "S" 書式指定子を使用して ToString(String) メソッドを呼び出す。By calling the ToString(String) method with the "s" format specifier.

  • "Ss" 書式指定子を使用して ToString(String) メソッドを呼び出す。By calling the ToString(String) method with the "ss" format specifier.

DateTimeOffset theTime = new DateTimeOffset(2008, 6, 12, 21, 16, 32, 
                             DateTimeOffset.Now.Offset);
Console.WriteLine("The second component of {0} is {1}.", 
                  theTime, theTime.Second);

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

Console.WriteLine("The second component of {0} is {1}.", 
                  theTime, theTime.ToString("ss"));
// The example produces the following output:
//    The second component of 6/12/2008 9:16:32 PM -07:00 is 32.
//    The second component of 6/12/2008 9:16:32 PM -07:00 is 32.
//    The second component of 6/12/2008 9:16:32 PM -07:00 is 32.
Dim theTime As New DateTimeOffset(#6/12/2008 9:16:32PM#, _
                                       DateTimeOffset.Now.Offset)
Console.WriteLine("The second component of {0} is {1}.", _
                  theTime, theTime.Second)

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

Console.WriteLine("The second component of {0} is {1}.", _
                  theTime, theTime.ToString("ss"))
' The example produces the following output:
'    The second component of 6/12/2008 9:16:32 PM -07:00 is 32.
'    The second component of 6/12/2008 9:16:32 PM -07:00 is 32.
'    The second component of 6/12/2008 9:16:32 PM -07:00 is 32.

注釈

Second プロパティは、Offset プロパティの値の影響を受けません。The Second property is not affected by the value of the Offset property.

また、"s" または "ss" カスタム書式指定子を使用して ToString メソッドを呼び出すことによって、DateTimeOffset オブジェクトの2番目のコンポーネントの文字列形式を作成することもできます。You can also create a string representation of a DateTimeOffset object's second component by calling the ToString method with the "s", or "ss" custom format specifiers.

適用対象