DateTimeOffset.Second 属性

定义

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

C#
public int Second { get; }

属性值

Int32

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

示例

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

C#
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.

注解

Second 属性不受该属性的值 Offset 的影响。

还可以通过使用“s”或“ss”自定义格式说明符调用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
.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
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0