DateTimeOffset.Second 属性

定义

获取由当前 DateTimeOffset 对象所表示的时钟时间的秒组成部分。

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

属性值

Int32

DateTimeOffset 对象的秒组成部分,以 0 到 59 之间的一个整数值来表示。

示例

以下示例以三种不同的方式显示对象的第二个 DateTimeOffset 组件:

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.
let theTime = DateTimeOffset(2008, 6, 12, 21, 16, 32, DateTimeOffset.Now.Offset)
printfn $"The second component of {theTime} is {theTime.Second}."

printfn $"""The second component of {theTime} is{theTime.ToString " s"}."""

printfn $"The second component of {theTime} is {theTime: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 的影响。

还可以通过使用“s”或“ss”自定义格式说明符调用ToString方法来创建对象的第二个DateTimeOffset组件的字符串表示形式。

适用于