TimeSpan.TotalSeconds 属性

定义

获取以整秒数和秒的小数部分表示的当前 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 属性表示整秒。

适用于

另请参阅