共用方式為


TimeSpan.TotalDays 屬性

定義

取得目前 TimeSpan 結構的值,這個值以整數和小數的天數表示。

public:
 property double TotalDays { double get(); };
public double TotalDays { get; }
member this.TotalDays : double
Public ReadOnly Property TotalDays As Double

屬性值

Double

這個執行個體表示的完整天數。

範例

下列範例會具現化 TimeSpan 物件,並顯示其屬性的值 TotalDays 。 它也會顯示每個元件的值 (小時、分鐘、秒、毫秒) ,形成其屬性值的小數部分 TotalDays

// Define an interval of 3 days, 16+ hours.
TimeSpan interval = new TimeSpan(3, 16, 42, 45, 750); 
Console.WriteLine("Value of TimeSpan: {0}", interval);

Console.WriteLine("{0:N5} days, as follows:", interval.TotalDays);
Console.WriteLine("   Days:         {0,3}", interval.Days);
Console.WriteLine("   Hours:        {0,3}", interval.Hours);
Console.WriteLine("   Minutes:      {0,3}", interval.Minutes);
Console.WriteLine("   Seconds:      {0,3}", interval.Seconds);
Console.WriteLine("   Milliseconds: {0,3}", interval.Milliseconds);

// The example displays the following output:
//       Value of TimeSpan: 3.16:42:45.7500000
//       3.69636 days, as follows:
//          Days:           3
//          Hours:         16
//          Minutes:       42
//          Seconds:       45
//          Milliseconds: 750
Module Example
   Public Sub Main()
      ' Define an interval of 3 days, 16+ hours.
      Dim interval As New TimeSpan(3, 16, 42, 45, 750) 
      Console.WriteLine("Value of TimeSpan: {0}", interval)
      
      Console.WriteLine("{0:N5} days, as follows:", interval.TotalDays)
      Console.WriteLine("   Days:         {0,3}", interval.Days)
      Console.WriteLine("   Hours:        {0,3}", interval.Hours)
      Console.WriteLine("   Minutes:      {0,3}", interval.Minutes)
      Console.WriteLine("   Seconds:      {0,3}", interval.Seconds)
      Console.WriteLine("   Milliseconds: {0,3}", interval.Milliseconds)
   End Sub
End Module
' The example displays the following output:
'       Value of TimeSpan: 3.16:42:45.7500000
'       3.69636 days, as follows:
'          Days:           3
'          Hours:         16
'          Minutes:       42
'          Seconds:       45
'          Milliseconds: 750

備註

這個屬性會將這個實例的值從刻度轉換成天。 此數目可能包含整數和小數天數。

TotalDays屬性代表整數和小數天數,而屬性則 Days 代表整天。

適用於

另請參閱