TimeSpan.TotalSeconds 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得目前 TimeSpan 結構的值,這個值以整數和小數的秒數表示。
public:
property double TotalSeconds { double get(); };
public double TotalSeconds { get; }
member this.TotalSeconds : double
Public ReadOnly Property TotalSeconds As Double
屬性值
這個執行個體表示的完整秒數。
範例
下列範例會具現化 TimeSpan 物件,並顯示其 TotalSeconds 屬性的值。 它也會顯示其毫秒元件的值,這形成其 TotalSeconds 屬性值的小數部分。
// Define an interval of 1 day, 15+ hours.
TimeSpan interval = new TimeSpan(1, 15, 42, 45, 750);
Console.WriteLine("Value of TimeSpan: {0}", interval);
Console.WriteLine("{0:N5} seconds, as follows:", interval.TotalSeconds);
Console.WriteLine(" Seconds: {0,8:N0}", interval.Days * 24 * 60 * 60 +
interval.Hours *60 * 60 +
interval.Minutes * 60 +
interval.Seconds);
Console.WriteLine(" Milliseconds: {0,8}", interval.Milliseconds);
// The example displays the following output:
// Value of TimeSpan: 1.15:42:45.7500000
// 142,965.75000 seconds, as follows:
// Seconds: 142,965
// Milliseconds: 750
// Define an interval of 1 day, 15+ hours.
let interval = TimeSpan(1, 15, 42, 45, 750)
printfn $"Value of TimeSpan: {interval}"
printfn $"{interval.TotalSeconds:N5} seconds, as follows:"
printfn $" Seconds: {interval.Days * 24 * 60 * 60 +
interval.Hours *60 * 60 +
interval.Minutes * 60 +
interval.Seconds,8:N0}"
printfn $" Milliseconds: {interval.Milliseconds,8}"
// The example displays the following output:
// Value of TimeSpan: 1.15:42:45.7500000
// 142,965.75000 seconds, as follows:
// Seconds: 142,965
// Milliseconds: 750
Module Example
Public Sub Main()
' Define an interval of 1 day, 15+ hours.
Dim interval As New TimeSpan(1, 15, 42, 45, 750)
Console.WriteLine("Value of TimeSpan: {0}", interval)
Console.WriteLine("{0:N5} seconds, as follows:", interval.TotalSeconds)
Console.WriteLine(" Seconds: {0,8:N0}", interval.Days * 24 * 60 * 60 + _
interval.Hours *60 * 60 + _
interval.Minutes * 60 + _
interval.Seconds)
Console.WriteLine(" Milliseconds: {0,8}", interval.Milliseconds)
End Sub
End Module
' The example displays the following output:
' Value of TimeSpan: 1.15:42:45.7500000
' 142,965.75000 seconds, as follows:
' Seconds: 142,965
' Milliseconds: 750
備註
這個屬性會將這個實例的值從刻度轉換為秒。 此數位可能包含整數和小數秒。
屬性 TotalSeconds 代表整數和小數秒,而 Seconds 屬性則代表整秒。