DateTimeOffset.Second 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得目前 DateTimeOffset 物件所表示之時鐘時間的秒數元件。
public:
property int Second { int get(); };
public int Second { get; }
member this.Second : int
Public ReadOnly Property Second As Integer
屬性值
DateTimeOffset 物件的秒數元件,以 0 到 59 之間的整數表示。
範例
下列範例會以三種不同的方式顯示 物件的第二個 DateTimeOffset 元件:
藉由擷取 屬性的值 Second 。
使用 「s」 格式規範呼叫 ToString(String) 方法。
使用 「ss」 格式規範呼叫 ToString(String) 方法。
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 元件的字串表示。