TimeSpan 結構
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
表示時間間隔。
public value class TimeSpan : IComparable, IComparable<TimeSpan>, IEquatable<TimeSpan>, IFormattable
public value class TimeSpan : IComparable, IComparable<TimeSpan>, IEquatable<TimeSpan>, IParsable<TimeSpan>, ISpanFormattable, ISpanParsable<TimeSpan>, IUtf8SpanFormattable
public value class TimeSpan : IComparable, IComparable<TimeSpan>, IEquatable<TimeSpan>, ISpanFormattable
public value class TimeSpan : IComparable, IComparable<TimeSpan>, IEquatable<TimeSpan>, IParsable<TimeSpan>, ISpanFormattable, ISpanParsable<TimeSpan>
public value class TimeSpan : IComparable
public value class TimeSpan : IComparable, IComparable<TimeSpan>, IEquatable<TimeSpan>
public struct TimeSpan : IComparable, IComparable<TimeSpan>, IEquatable<TimeSpan>, IFormattable
public readonly struct TimeSpan : IComparable, IComparable<TimeSpan>, IEquatable<TimeSpan>, IParsable<TimeSpan>, ISpanFormattable, ISpanParsable<TimeSpan>, IUtf8SpanFormattable
public readonly struct TimeSpan : IComparable, IComparable<TimeSpan>, IEquatable<TimeSpan>, IFormattable
public readonly struct TimeSpan : IComparable, IComparable<TimeSpan>, IEquatable<TimeSpan>, ISpanFormattable
public readonly struct TimeSpan : IComparable, IComparable<TimeSpan>, IEquatable<TimeSpan>, IParsable<TimeSpan>, ISpanFormattable, ISpanParsable<TimeSpan>
[System.Serializable]
public struct TimeSpan : IComparable
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public struct TimeSpan : IComparable, IComparable<TimeSpan>, IEquatable<TimeSpan>
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public struct TimeSpan : IComparable, IComparable<TimeSpan>, IEquatable<TimeSpan>, IFormattable
type TimeSpan = struct
interface IFormattable
type TimeSpan = struct
interface IFormattable
interface IParsable<TimeSpan>
interface ISpanFormattable
interface ISpanParsable<TimeSpan>
interface IUtf8SpanFormattable
type TimeSpan = struct
interface ISpanFormattable
interface IFormattable
type TimeSpan = struct
interface IFormattable
interface IParsable<TimeSpan>
interface ISpanFormattable
interface ISpanParsable<TimeSpan>
[<System.Serializable>]
type TimeSpan = struct
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type TimeSpan = struct
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type TimeSpan = struct
interface IFormattable
Public Structure TimeSpan
Implements IComparable, IComparable(Of TimeSpan), IEquatable(Of TimeSpan), IFormattable
Public Structure TimeSpan
Implements IComparable, IComparable(Of TimeSpan), IEquatable(Of TimeSpan), IParsable(Of TimeSpan), ISpanFormattable, ISpanParsable(Of TimeSpan), IUtf8SpanFormattable
Public Structure TimeSpan
Implements IComparable, IComparable(Of TimeSpan), IEquatable(Of TimeSpan), ISpanFormattable
Public Structure TimeSpan
Implements IComparable, IComparable(Of TimeSpan), IEquatable(Of TimeSpan), IParsable(Of TimeSpan), ISpanFormattable, ISpanParsable(Of TimeSpan)
Public Structure TimeSpan
Implements IComparable
Public Structure TimeSpan
Implements IComparable, IComparable(Of TimeSpan), IEquatable(Of TimeSpan)
- 繼承
- 屬性
- 實作
範例
以下範例實例化一個 TimeSpan 物件,代表兩個日期之間的差異。 接著它會顯示物件 TimeSpan 的屬性。
// Define two dates.
DateTime date1 = new DateTime(2010, 1, 1, 8, 0, 15);
DateTime date2 = new DateTime(2010, 8, 18, 13, 30, 30);
// Calculate the interval between the two dates.
TimeSpan interval = date2 - date1;
Console.WriteLine("{0} - {1} = {2}", date2, date1, interval.ToString());
// Display individual properties of the resulting TimeSpan object.
Console.WriteLine(" {0,-35} {1,20}", "Value of Days Component:", interval.Days);
Console.WriteLine(" {0,-35} {1,20}", "Total Number of Days:", interval.TotalDays);
Console.WriteLine(" {0,-35} {1,20}", "Value of Hours Component:", interval.Hours);
Console.WriteLine(" {0,-35} {1,20}", "Total Number of Hours:", interval.TotalHours);
Console.WriteLine(" {0,-35} {1,20}", "Value of Minutes Component:", interval.Minutes);
Console.WriteLine(" {0,-35} {1,20}", "Total Number of Minutes:", interval.TotalMinutes);
Console.WriteLine(" {0,-35} {1,20:N0}", "Value of Seconds Component:", interval.Seconds);
Console.WriteLine(" {0,-35} {1,20:N0}", "Total Number of Seconds:", interval.TotalSeconds);
Console.WriteLine(" {0,-35} {1,20:N0}", "Value of Milliseconds Component:", interval.Milliseconds);
Console.WriteLine(" {0,-35} {1,20:N0}", "Total Number of Milliseconds:", interval.TotalMilliseconds);
Console.WriteLine(" {0,-35} {1,20:N0}", "Ticks:", interval.Ticks);
// This example displays the following output:
// 8/18/2010 1:30:30 PM - 1/1/2010 8:00:15 AM = 229.05:30:15
// Value of Days Component: 229
// Total Number of Days: 229.229340277778
// Value of Hours Component: 5
// Total Number of Hours: 5501.50416666667
// Value of Minutes Component: 30
// Total Number of Minutes: 330090.25
// Value of Seconds Component: 15
// Total Number of Seconds: 19,805,415
// Value of Milliseconds Component: 0
// Total Number of Milliseconds: 19,805,415,000
// Ticks: 198,054,150,000,000
// Define two dates.
let date1 = DateTime(2010, 1, 1, 8, 0, 15)
let date2 = DateTime(2010, 8, 18, 13, 30, 30)
// Calculate the interval between the two dates.
let interval = date2 - date1
printfn $"{date2} - {date1} = {interval}"
// Display individual properties of the resulting TimeSpan object.
printfn $""" {"Value of Days Component:",-35} {interval.Days,20}"""
printfn $""" {"Total Number of Days:",-35} {interval.TotalDays,20}"""
printfn $""" {"Value of Hours Component:",-35} {interval.Hours,20}"""
printfn $""" {"Total Number of Hours:",-35} {interval.TotalHours,20}"""
printfn $""" {"Value of Minutes Component:",-35} {interval.Minutes,20}"""
printfn $""" {"Total Number of Minutes:",-35} {interval.TotalMinutes,20}"""
printfn $""" {"Value of Seconds Component:",-35} {interval.Seconds,20:N0}"""
printfn $""" {"Total Number of Seconds:",-35} {interval.TotalSeconds,20:N0}"""
printfn $""" {"Value of Milliseconds Component:",-35} {interval.Milliseconds,20:N0}"""
printfn $""" {"Total Number of Milliseconds:",-35} {interval.TotalMilliseconds,20:N0}"""
printfn $""" {"Ticks:",-35} {interval.Ticks,20:N0}"""
// This example displays the following output:
// 8/18/2010 1:30:30 PM - 1/1/2010 8:00:15 AM = 229.05:30:15
// Value of Days Component: 229
// Total Number of Days: 229.229340277778
// Value of Hours Component: 5
// Total Number of Hours: 5501.50416666667
// Value of Minutes Component: 30
// Total Number of Minutes: 330090.25
// Value of Seconds Component: 15
// Total Number of Seconds: 19,805,415
// Value of Milliseconds Component: 0
// Total Number of Milliseconds: 19,805,415,000
// Ticks: 198,054,150,000,000
' Define two dates.
Dim date1 As Date = #1/1/2010 8:00:15AM#
Dim date2 As Date = #8/18/2010 1:30:30PM#
' Calculate the interval between the two dates.
Dim interval As TimeSpan = date2 - date1
Console.WriteLine("{0} - {1} = {2}", date2, date1, interval.ToString())
' Display individual properties of the resulting TimeSpan object.
Console.WriteLine(" {0,-35} {1,20}", "Value of Days Component:", interval.Days)
Console.WriteLine(" {0,-35} {1,20}", "Total Number of Days:", interval.TotalDays)
Console.WriteLine(" {0,-35} {1,20}", "Value of Hours Component:", interval.Hours)
Console.WriteLine(" {0,-35} {1,20}", "Total Number of Hours:", interval.TotalHours)
Console.WriteLine(" {0,-35} {1,20}", "Value of Minutes Component:", interval.Minutes)
Console.WriteLine(" {0,-35} {1,20}", "Total Number of Minutes:", interval.TotalMinutes)
Console.WriteLine(" {0,-35} {1,20:N0}", "Value of Seconds Component:", interval.Seconds)
Console.WriteLine(" {0,-35} {1,20:N0}", "Total Number of Seconds:", interval.TotalSeconds)
Console.WriteLine(" {0,-35} {1,20:N0}", "Value of Milliseconds Component:", interval.Milliseconds)
Console.WriteLine(" {0,-35} {1,20:N0}", "Total Number of Milliseconds:", interval.TotalMilliseconds)
Console.WriteLine(" {0,-35} {1,20:N0}", "Ticks:", interval.Ticks)
' The example displays the following output:
' 8/18/2010 1:30:30 PM - 1/1/2010 8:00:15 AM = 229.05:30:15
' Value of Days Component: 229
' Total Number of Days: 229.229340277778
' Value of Hours Component: 5
' Total Number of Hours: 5501.50416666667
' Value of Minutes Component: 30
' Total Number of Minutes: 330090.25
' Value of Seconds Component: 15
' Total Number of Seconds: 19,805,415
' Value of Milliseconds Component: 0
' Total Number of Milliseconds: 19,805,415,000
' Ticks: 198,054,150,000,000
# Define two dates.
$Date2 = Get-Date -Date '2010/8/18' -Hour 13 -Minute 30 -Second 30
$Date1 = Get-Date -Date '2010/1/1' -Hour 8 -Minute 0 -Second 15
# Calculate the interval between the two dates.
$Interval = $Date2 - $Date1
"{0} - {1} = {2}" -f $Date2, $Date1, ($Interval.ToString())
# Display individual properties of the resulting TimeSpan object.
" {0,-35} {1,20}" -f "Value of Days Component:", $Interval.Days
" {0,-35} {1,20}" -f "Total Number of Days:", $Interval.TotalDays
" {0,-35} {1,20}" -f "Value of Hours Component:", $Interval.Hours
" {0,-35} {1,20}" -f "Total Number of Hours:", $Interval.TotalHours
" {0,-35} {1,20}" -f "Value of Minutes Component:", $Interval.Minutes
" {0,-35} {1,20}" -f "Total Number of Minutes:", $Interval.TotalMinutes
" {0,-35} {1,20:N0}" -f "Value of Seconds Component:", $Interval.Seconds
" {0,-35} {1,20:N0}" -f "Total Number of Seconds:", $Interval.TotalSeconds
" {0,-35} {1,20:N0}" -f "Value of Milliseconds Component:", $Interval.Milliseconds
" {0,-35} {1,20:N0}" -f "Total Number of Milliseconds:", $Interval.TotalMilliseconds
" {0,-35} {1,20:N0}" -f "Ticks:", $Interval.Ticks
<# This sample produces the following output:
18/08/2010 13:30:30 - 01/01/2010 08:00:15 = 229.05:30:15
Value of Days Component: 229
Total Number of Days: 229.229340277778
Value of Hours Component: 5
Total Number of Hours: 5501.50416666667
Value of Minutes Component: 30
Total Number of Minutes: 330090.25
Value of Seconds Component: 15
Total Number of Seconds: 19,805,415
Value of Milliseconds Component: 0
Total Number of Milliseconds: 19,805,415,000
Ticks: 198,054,150,000,000
#>
備註
TimeSpan物件表示時間間隔(持續時間或經過的時間),以正或負的天數、小時、分鐘、秒和秒的分數計量。 結構 TimeSpan 也可以用來代表一天的時間,但只有當時間與特定日期無關時。 否則,應該使用 DateTime 或 DateTimeOffset 結構。 (如需使用 TimeSpan 結構反映一天時間的詳細資訊,請參閱 選擇 DateTime、DateTimeOffset、TimeSpan 和 TimeZoneInfo。)
Note
值 TimeSpan 代表時間間隔,而且可以表示為特定天數、小時、分鐘、秒和毫秒。 因為它代表著一個不參考特定起點或終點的一般時間間隔,所以不能用年和月來表示,因為這兩者的天數是不固定的。 它與 DateTime 值不同,該值代表日期和時間,而不參考特定時區,或 DateTimeOffset 代表特定時間刻度的值。
結構用來測量持續時間的最大時間 TimeSpan 單位是一天。 時間間隔是以天為單位來測量一致性,因為較大的時間單位天數,例如月和年,會有所不同。
物件的值 TimeSpan 是等於所表示時間間隔的刻度數。 一個刻度等於 100 奈秒,即一千萬分之一秒。 物件的值 TimeSpan 範圍可以從 到 TimeSpan.MinValueTimeSpan.MaxValue。
具現化 TimeSpan 值
您可以透過數種方式具現化 TimeSpan 值:
藉由呼叫其隱含無參數建構函式。 這會建立值為 TimeSpan.Zero的物件,如下列範例所示。
TimeSpan interval = new TimeSpan(); Console.WriteLine(interval.Equals(TimeSpan.Zero)); // Displays "True".let interval = TimeSpan() printfn $"{interval.Equals TimeSpan.Zero}" // Displays "True".Dim interval As New TimeSpan() Console.WriteLine(interval.Equals(TimeSpan.Zero)) ' Displays "True".藉由呼叫其中一個明確的構造函數。 下列範例會將 TimeSpan 值初始化為指定的小時、分和秒數。
TimeSpan interval = new TimeSpan(2, 14, 18); Console.WriteLine(interval.ToString()); // Displays "02:14:18".let interval = TimeSpan(2, 14, 18) printfn $"{interval}" // Displays "02:14:18".Dim interval As New TimeSpan(2, 14, 18) Console.WriteLine(interval.ToString()) ' Displays "02:14:18".呼叫方法或執行傳回TimeSpan值的操作。 例如,您可以具現化代表兩個 TimeSpan 日期和時間值之間間隔的值,如下列範例所示。
DateTime departure = new DateTime(2010, 6, 12, 18, 32, 0); DateTime arrival = new DateTime(2010, 6, 13, 22, 47, 0); TimeSpan travelTime = arrival - departure; Console.WriteLine($"{arrival} - {departure} = {travelTime}"); // The example displays the following output: // 6/13/2010 10:47:00 PM - 6/12/2010 6:32:00 PM = 1.04:15:00let departure = DateTime(2010, 6, 12, 18, 32, 0) let arrival = DateTime(2010, 6, 13, 22, 47, 0) let travelTime = arrival - departure printfn $"{arrival} - {departure} = {travelTime}" // The example displays the following output: // 6/13/2010 10:47:00 PM - 6/12/2010 6:32:00 PM = 1.04:15:00Dim departure As DateTime = #06/12/2010 6:32PM# Dim arrival As DateTime = #06/13/2010 10:47PM# Dim travelTime As TimeSpan = arrival - departure Console.WriteLine("{0} - {1} = {2}", arrival, departure, travelTime) ' The example displays the following output: ' 6/13/2010 10:47:00 PM - 6/12/2010 6:32:00 PM = 1.04:15:00您也可以以此方式將 物件初始化 TimeSpan 為零時間值,如下列範例所示。
Random rnd = new Random(); TimeSpan timeSpent = TimeSpan.Zero; timeSpent += GetTimeBeforeLunch(); timeSpent += GetTimeAfterLunch(); Console.WriteLine($"Total time: {timeSpent}"); TimeSpan GetTimeBeforeLunch() { return new TimeSpan(rnd.Next(3, 6), 0, 0); } TimeSpan GetTimeAfterLunch() { return new TimeSpan(rnd.Next(3, 6), 0, 0); } // The example displays output like the following: // Total time: 08:00:00open System let rnd = Random() let getTimeBeforeLunch () = TimeSpan(rnd.Next(3, 6), 0, 0) let getTimeAfterLunch() = TimeSpan(rnd.Next(3, 6), 0, 0) do let timeSpent = TimeSpan.Zero let timeSpent = timeSpent + getTimeBeforeLunch () let timeSpent = timeSpent + getTimeAfterLunch () printfn $"Total time: {timeSpent}" // The example displays output like the following: // Total time: 08:00:00Module MExample Dim rnd As New Random() Public Sub Main() Dim timeSpent As TimeSpan = TimeSpan.Zero timeSpent += GetTimeBeforeLunch() timeSpent += GetTimeAfterLunch() Console.WriteLine("Total time: {0}", timeSpent) End Sub Private Function GetTimeBeforeLunch() As TimeSpan Return New TimeSpan(rnd.Next(3, 6), 0, 0) End Function Private Function GetTimeAfterLunch() As TimeSpan Return New TimeSpan(rnd.Next(3, 6), 0, 0) End Function End Module ' The example displays output like the following: ' Total time: 08:00:00TimeSpan值是由DateTime、DateTimeOffset和TimeSpan結構的算術運算元和方法所傳回。
藉由剖析TimeSpan值的字串表示方式。 您可以使用 Parse 和 TryParse 方法,將包含時間間隔的 TimeSpan 字串轉換成值。 下列範例會使用 Parse 方法,將字串陣列轉換成 TimeSpan 值。
string[] values = { "12", "31.", "5.8:32:16", "12:12:15.95", ".12"}; foreach (string value in values) { try { TimeSpan ts = TimeSpan.Parse(value); Console.WriteLine($"'{value}' --> {ts}"); } catch (FormatException) { Console.WriteLine($"Unable to parse '{value}'"); } catch (OverflowException) { Console.WriteLine($"'{value}' is outside the range of a TimeSpan."); } } // The example displays the following output: // '12' --> 12.00:00:00 // Unable to parse '31.' // '5.8:32:16' --> 5.08:32:16 // '12:12:15.95' --> 12:12:15.9500000 // Unable to parse '.12'let values = [| "12"; "31."; "5.8:32:16"; "12:12:15.95"; ".12" |] for value in values do try let ts = TimeSpan.Parse value printfn $"'{value}' --> {ts}" with | :? FormatException -> printfn $"Unable to parse '{value}'" | :? OverflowException -> printfn $"'{value}' is outside the range of a TimeSpan." // The example displays the following output: // '12' --> 12.00:00:00 // Unable to parse '31.' // '5.8:32:16' --> 5.08:32:16 // '12:12:15.95' --> 12:12:15.9500000 // Unable to parse '.12'Dim values() As String = {"12", "31.", "5.8:32:16", "12:12:15.95", ".12"} For Each value As String In values Try Dim ts As TimeSpan = TimeSpan.Parse(value) Console.WriteLine("'{0}' --> {1}", value, ts) Catch e As FormatException Console.WriteLine("Unable to parse '{0}'", value) Catch e As OverflowException Console.WriteLine("'{0}' is outside the range of a TimeSpan.", value) End Try Next ' The example displays the following output: ' '12' --> 12.00:00:00 ' Unable to parse '31.' ' '5.8:32:16' --> 5.08:32:16 ' '12:12:15.95' --> 12:12:15.9500000 ' Unable to parse '.12'此外,您可以呼叫 TimeSpan 或 ParseExact 方法,定義要剖析和轉換成TryParseExact值的輸入字串精確格式。
對 TimeSpan 值執行作業
您可以使用 Addition 和 Subtraction 運算符,或呼叫 Add 和 Subtract 方法來加法和減去時間持續時間。 您也可以呼叫 Compare、 CompareTo和 Equals 方法來比較兩個時間持續時間。 結構 TimeSpan 也包含 Duration 和 Negate 方法,可將時間間隔轉換為正值和負值。
格式化 TimeSpan 值
TimeSpan值可以表示為 [-]d:hh:mm:ss.ff,其中選擇性負號表示負時間間隔,d 元件為天,hh 是以24小時制為單位的小時,mm 為分鐘,ss 為秒,ff 為秒的小數部分。 也就是說,時間間隔可以是由正數或負數天數組成,不帶特定時間,或者是包含特定時間的天數,或者僅表示一天中的某個時間。
該 TimeSpan 結構透過方法的超載 ToString 支援文化敏感格式,該方法將值 TimeSpan 轉換為字串表示。 TimeSpan.ToString(String) 重載可讓您指定格式字串,以定義時間間隔的字串表示。 重載TimeSpan.ToString(String, IFormatProvider)可讓您指定格式字串和時間間隔的字串表示中要使用之格式慣例的文化特性。 TimeSpan 支援標準和自定義格式字串。 (如需詳細資訊,請參閱 標準 TimeSpan 格式字串 和 自訂 TimeSpan 格式字串。)不過,只有標準格式字串會區分文化特性。
建構函式
| 名稱 | Description |
|---|---|
| TimeSpan(Int32, Int32, Int32, Int32, Int32, Int32) |
將結構的新實例 TimeSpan 初始化為指定的天數、小時、分鐘、秒、毫秒及微秒。 |
| TimeSpan(Int32, Int32, Int32, Int32, Int32) |
初始化結構的新實例 TimeSpan ,時間為指定的天、小時、分鐘、秒和毫秒。 |
| TimeSpan(Int32, Int32, Int32, Int32) |
初始化結構的新實例 TimeSpan ,設定在指定的天數、小時、分鐘和秒數。 |
| TimeSpan(Int32, Int32, Int32) |
初始化結構的新實例 TimeSpan ,設定為指定的小時、分鐘和秒數。 |
| TimeSpan(Int64) |
將結構的新實例 TimeSpan 初始化為指定的脈次數。 |
欄位
| 名稱 | Description |
|---|---|
| HoursPerDay |
代表一天的時數。 此欄位是常數。 |
| MaxValue |
代表最大 TimeSpan 值。 此欄位僅供讀取。 |
| MicrosecondsPerDay |
代表一天內的微秒數。 此欄位是常數。 |
| MicrosecondsPerHour |
代表一小時內的微秒數。 此欄位是常數。 |
| MicrosecondsPerMillisecond |
代表1毫秒的微秒數。 此欄位是常數。 |
| MicrosecondsPerMinute |
代表1分鐘內的微秒數。 此欄位是常數。 |
| MicrosecondsPerSecond |
代表1秒內的微秒數。 此欄位是常數。 |
| MillisecondsPerDay |
代表一天內的毫秒數。 此欄位是常數。 |
| MillisecondsPerHour |
代表一小時中的毫秒數。 此欄位是常數。 |
| MillisecondsPerMinute |
代表1分鐘中的毫秒數。 此欄位是常數。 |
| MillisecondsPerSecond |
代表1秒內的毫秒數。 此欄位是常數。 |
| MinutesPerDay |
代表一天內的分鐘數。 此欄位是常數。 |
| MinutesPerHour |
代表一小時的分鐘數。 此欄位是常數。 |
| MinValue |
代表最小 TimeSpan 值。 此欄位僅供讀取。 |
| NanosecondsPerTick |
代表每刻奈秒數。 此欄位是常數。 |
| SecondsPerDay |
代表一天中的秒數。 此欄位是常數。 |
| SecondsPerHour |
代表一小時中的秒數。 此欄位是常數。 |
| SecondsPerMinute |
代表每分鐘的秒數。 此欄位是常數。 |
| TicksPerDay |
代表一天內的蜱蟲數量。 此欄位是常數。 |
| TicksPerHour |
代表一小時內的刻數。 此欄位是常數。 |
| TicksPerMicrosecond |
代表1微秒內的tick數。 此欄位是常數。 |
| TicksPerMillisecond |
代表 1 毫秒內的刻數。 此欄位是常數。 |
| TicksPerMinute |
代表每分鐘的tick數。 此欄位是常數。 |
| TicksPerSecond |
代表每秒的刻數。 |
| Zero |
代表零 TimeSpan 值。 此欄位僅供讀取。 |
屬性
| 名稱 | Description |
|---|---|
| Days |
取得由目前 TimeSpan 結構所代表的時間區間中的天數成分。 |
| Hours |
取得目前 TimeSpan 結構所代表的時間區間中的工時成分。 |
| Microseconds |
取得由當前 TimeSpan 結構所代表的時間區間中微秒分量。 |
| Milliseconds |
得到由當前 TimeSpan 結構所代表的時間區間中的毫秒分量。 |
| Minutes |
取得由目前 TimeSpan 結構表示的時間區間中的分鐘成分。 |
| Nanoseconds |
得到由當前 TimeSpan 結構所代表的時間區間中的奈秒分量。 |
| Seconds |
取得由當前 TimeSpan 結構表示的時間區間中的秒分量。 |
| Ticks |
取得代表當前 TimeSpan 結構值的刻數。 |
| TotalDays |
取得當前 TimeSpan 結構的價值,以整日及分數日表示。 |
| TotalHours |
以全工時和分工時表示的現有 TimeSpan 結構價值。 |
| TotalMicroseconds |
可獲得以整微秒與分微秒表示的當前 TimeSpan 結構值。 |
| TotalMilliseconds |
取得當前 TimeSpan 結構的數值,以整數與分毫秒表示。 |
| TotalMinutes |
取得目前 TimeSpan 結構的數值,以整分鐘和分數分鐘表示。 |
| TotalNanoseconds |
得到以整奈秒和分數奈秒表示的當前 TimeSpan 結構值。 |
| TotalSeconds |
以整秒和分秒表示當前 TimeSpan 結構的值。 |
方法
操作員
| 名稱 | Description |
|---|---|
| Addition(TimeSpan, TimeSpan) |
新增兩個指定的 TimeSpan 實例。 |
| Division(TimeSpan, Double) |
回傳一個新 TimeSpan 物件,其值是將指定 |
| Division(TimeSpan, TimeSpan) |
回傳一個新值,該值是除Double以 |
| Equality(TimeSpan, TimeSpan) |
表示兩個 TimeSpan 實例是否相等。 |
| GreaterThan(TimeSpan, TimeSpan) | |
| GreaterThanOrEqual(TimeSpan, TimeSpan) | |
| Inequality(TimeSpan, TimeSpan) |
表示兩個 TimeSpan 實例是否不相等。 |
| LessThan(TimeSpan, TimeSpan) | |
| LessThanOrEqual(TimeSpan, TimeSpan) | |
| Multiply(Double, TimeSpan) |
回傳一個新 TimeSpan 物件,其值是將指定 |
| Multiply(TimeSpan, Double) |
回傳一個新 TimeSpan 物件,其值是將指定 |
| Subtraction(TimeSpan, TimeSpan) | |
| UnaryNegation(TimeSpan) |
回傳 a TimeSpan ,其值為指定實例的否定值。 |
| UnaryPlus(TimeSpan) |
回傳指定的 實例 TimeSpan。 |
明確介面實作
| 名稱 | Description |
|---|---|
| IComparable.CompareTo(Object) |
將此實例與指定物件比較,並回傳一個整數,表示該實例是短於指定物件、等於或長。 |