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 之间进行选择”。)
注释
值 TimeSpan 表示时间间隔,可以表示为特定的天数、小时、分钟、秒和毫秒。 由于它表示不引用特定起点或终点的一般间隔,因此不能以年和月来表示,这两者都有可变天数。 它不同于一个 DateTime 值,该值表示不引用特定时区的日期和时间,或 DateTimeOffset 表示特定时间刻度的值。
结构用于度量持续时间的最大时间 TimeSpan 单位是一天。 时间间隔以天为单位来衡量一致性,因为以较大的时间单位(如月份和年份)的天数不同。
TimeSpan 对象的值是等于所表示的时间间隔的刻度数。 滴答值等于 100 纳秒,即一千万分之一秒。 TimeSpan 对象的值可以介于 TimeSpan.MinValue 到 TimeSpan.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结构还包括将DurationNegate时间间隔转换为正值和负值的方法,
TimeSpan 值的范围是 MinValue 到 MaxValue。
格式化 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 格式字符串。)但是,只有标准格式字符串是对文化敏感的。
构造函数
| 名称 | 说明 |
|---|---|
| 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 初始化为指定的时钟周期数。 |
字段
| 名称 | 说明 |
|---|---|
| HoursPerDay |
表示 1 天内的小时数。 此字段为常量。 |
| MaxValue |
表示最大值 TimeSpan 。 此字段是只读的。 |
| MicrosecondsPerDay |
表示 1 天内的微秒数。 此字段为常量。 |
| MicrosecondsPerHour |
表示 1 小时内的微秒数。 此字段为常量。 |
| MicrosecondsPerMillisecond |
表示以 1 毫秒为单位的微秒数。 此字段为常量。 |
| MicrosecondsPerMinute |
表示 1 分钟内的微秒数。 此字段为常量。 |
| MicrosecondsPerSecond |
表示 1 秒中的微秒数。 此字段为常量。 |
| MillisecondsPerDay |
表示 1 天内的毫秒数。 此字段为常量。 |
| MillisecondsPerHour |
表示 1 小时内的毫秒数。 此字段为常量。 |
| MillisecondsPerMinute |
表示 1 分钟内的毫秒数。 此字段为常量。 |
| MillisecondsPerSecond |
表示 1 秒中的毫秒数。 此字段为常量。 |
| MinutesPerDay |
表示 1 天内的分钟数。 此字段为常量。 |
| MinutesPerHour |
表示 1 小时内的分钟数。 此字段为常量。 |
| MinValue |
表示最小值 TimeSpan 。 此字段是只读的。 |
| NanosecondsPerTick |
表示每个刻度数的纳秒数。 此字段为常量。 |
| SecondsPerDay |
表示 1 天内的秒数。 此字段为常量。 |
| SecondsPerHour |
表示 1 小时内的秒数。 此字段为常量。 |
| SecondsPerMinute |
表示 1 分钟内的秒数。 此字段为常量。 |
| TicksPerDay |
表示 1 天内的刻度数。 此字段为常量。 |
| TicksPerHour |
表示 1 小时内的刻度数。 此字段为常量。 |
| TicksPerMicrosecond |
表示以 1 微秒为单位的刻度数。 此字段为常量。 |
| TicksPerMillisecond |
表示以 1 毫秒为单位的刻度数。 此字段为常量。 |
| TicksPerMinute |
表示 1 分钟内的刻度数。 此字段为常量。 |
| TicksPerSecond |
表示 1 秒中的刻度数。 |
| Zero |
表示零 TimeSpan 值。 此字段是只读的。 |
属性
| 名称 | 说明 |
|---|---|
| Days |
获取由当前 TimeSpan 结构表示的时间间隔的天分量。 |
| Hours |
获取由当前 TimeSpan 结构表示的时间间隔的小时部分。 |
| Microseconds |
获取由当前 TimeSpan 结构表示的时间间隔的微秒部分。 |
| Milliseconds |
获取由当前 TimeSpan 结构表示的时间间隔的毫秒部分。 |
| Minutes |
获取由当前 TimeSpan 结构表示的时间间隔的分钟分量。 |
| Nanoseconds |
获取由当前 TimeSpan 结构表示的时间间隔的 nanoseconds 组件。 |
| Seconds |
获取由当前 TimeSpan 结构表示的时间间隔的秒部分。 |
| Ticks |
获取表示当前 TimeSpan 结构的值的刻度数。 |
| TotalDays |
获取以整数和小数天表示的当前 TimeSpan 结构的值。 |
| TotalHours |
获取以整小时和小数小时表示的当前 TimeSpan 结构的值。 |
| TotalMicroseconds |
获取以整数和小数微秒表示的当前 TimeSpan 结构的值。 |
| TotalMilliseconds |
获取以整数和小数毫秒表示的当前 TimeSpan 结构的值。 |
| TotalMinutes |
获取以整分钟和小数分钟表示的当前 TimeSpan 结构的值。 |
| TotalNanoseconds |
获取以整数和小数纳秒表示的当前 TimeSpan 结构的值。 |
| TotalSeconds |
获取以整秒和小数秒表示的当前 TimeSpan 结构的值。 |
方法
运营商
| 名称 | 说明 |
|---|---|
| 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) |
返回一个 TimeSpan 值是指定实例的否定值。 |
| UnaryPlus(TimeSpan) |
返回指定的 . 实例 TimeSpan。 |
显式接口实现
| 名称 | 说明 |
|---|---|
| IComparable.CompareTo(Object) |
将此实例与指定的对象进行比较,并返回一个整数,该整数指示此实例是短于、等于还是长于指定对象。 |