DateTimeOffset DateTimeOffset DateTimeOffset DateTimeOffset Struct

定义

表示一个时间点,通常以相对于协调世界时 (UTC) 的日期和时间来表示。 Represents a point in time, typically expressed as a date and time of day, relative to Coordinated Universal Time (UTC).

public value class DateTimeOffset : IComparable, IComparable<DateTimeOffset>, IEquatable<DateTimeOffset>, IFormattable, System::Runtime::Serialization::IDeserializationCallback, System::Runtime::Serialization::ISerializable
[Serializable]
public struct DateTimeOffset : IComparable, IComparable<DateTimeOffset>, IEquatable<DateTimeOffset>, IFormattable, System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable
type DateTimeOffset = struct
    interface IFormattable
    interface ISerializable
    interface IDeserializationCallback
Public Structure DateTimeOffset
Implements IComparable, IComparable(Of DateTimeOffset), IDeserializationCallback, IEquatable(Of DateTimeOffset), IFormattable, ISerializable
继承
DateTimeOffsetDateTimeOffsetDateTimeOffsetDateTimeOffset
属性
SerializableAttribute
实现

注解

DateTimeOffset结构包含DateTime值以及Offset属性,用于定义当前之间的差异DateTimeOffset实例的日期和时间与协调世界时 (UTC)。The DateTimeOffset structure includes a DateTime value, together with an Offset property that defines the difference between the current DateTimeOffset instance's date and time and Coordinated Universal Time (UTC). 它完全定义的日期和时间相对于 UTC,因为DateTimeOffset结构不包括Kind成员,作为DateTime结构。Because it exactly defines a date and time relative to UTC, the DateTimeOffset structure does not include a Kind member, as the DateTime structure does. 它表示日期和时间值采用 UTC 范围 12:00:00,年 1 月 1 日午夜 0001 午夜 11:59:59 止 (基督纪元) 到 11:59:59 PM,到公元 9999 年 12 月 31 日It represents dates and times with values whose UTC ranges from 12:00:00 midnight, January 1, 0001 Anno Domini (Common Era), to 11:59:59 P.M., December 31, 9999 A.D. (C.E.)。(C.E.).

时间部分的DateTimeOffset值以 100 毫微秒为单位称为计时周期,和特定日期是自午夜 12:00,公元 0001 年 1 月 1 日以来的计时周期数The time component of a DateTimeOffset value is measured in 100-nanosecond units called ticks, and a particular date is the number of ticks since 12:00 midnight, January 1, 0001 A.D. (C.E.)在GregorianCalendar日历。(C.E.) in the GregorianCalendar calendar. 一个DateTimeOffset值始终表示上下文的显式或默认日历中。A DateTimeOffset value is always expressed in the context of an explicit or default calendar. 中的计时周期总数不包括归因于闰秒为单位的计时周期数。Ticks that are attributable to leap seconds are not included in the total number of ticks.

备注

如果您正在使用计时周期值,你想要将转换为其他时间间隔,如分钟或秒,则应使用TimeSpan.TicksPerDayTimeSpan.TicksPerHourTimeSpan.TicksPerMinuteTimeSpan.TicksPerSecond,或TimeSpan.TicksPerMillisecond常量来执行此转换。If you are working with a ticks value that you want to convert to some other time interval, such as minutes or seconds, you should use the TimeSpan.TicksPerDay, TimeSpan.TicksPerHour, TimeSpan.TicksPerMinute, TimeSpan.TicksPerSecond, or TimeSpan.TicksPerMillisecond constant to perform the conversion. 例如,若要添加的秒数表示的时钟周期到指定数值Second组成部分DateTimeOffset值,可以使用表达式dateValue.Second + nTicks/Timespan.TicksPerSecondFor example, to add the number of seconds represented by a specified number of ticks to the Second component of a DateTimeOffset value, you can use the expression dateValue.Second + nTicks/Timespan.TicksPerSecond.

尽管DateTimeOffset值包含一个偏移量,它不是一种完全时区感知的数据结构。Although a DateTimeOffset value includes an offset, it is not a fully time zone-aware data structure. 一个特征的时区与 UTC 的偏移量时,它并不明确地标识一个时区。While an offset from UTC is one characteristic of a time zone, it does not unambiguously identify a time zone. 不仅执行多个时区具有相同的偏移量从 UTC,而且如果实行夏令时更改一个时区的偏移量。Not only do multiple time zones share the same offset from UTC, but the offset of a single time zone changes if it observes daylight saving time. 这意味着,只要DateTimeOffset值与其时区,它可以不再进行明确链接回其原始时区。This means that, as soon as a DateTimeOffset value is disassociated from its time zone, it can no longer be unambiguously linked back to its original time zone.

因为DateTimeOffset是一种结构,DateTimeOffset已声明但未初始化的对象包含的默认值为每个成员字段。Because DateTimeOffset is a structure, a DateTimeOffset object that has been declared but not otherwise initialized contains the default values for each of its member fields. 这意味着,其DateTime属性设置为DateTimeOffset.MinValue并将其Offset属性设置为TimeSpan.ZeroThis means that its DateTime property is set to DateTimeOffset.MinValue and its Offset property is set to TimeSpan.Zero.

您可以创建一个新DateTimeOffset通过调用其构造函数重载,它类似于重载构造任何的函数值DateTime结构。You can create a new DateTimeOffset value by calling any of the overloads of its constructor, which are similar to the overloaded constructors for the DateTime structure. 您还可以创建一个新DateTimeOffset通过将其分配值DateTime值。You can also create a new DateTimeOffset value by assigning it a DateTime value. 这是隐式转换;它不需要强制转换运算符 (在 C# 中) 或调用转换方法 (在 Visual Basic 中)。This is an implicit conversion; it does not require a casting operator (in C#) or call to a conversion method (in Visual Basic). 此外可以初始化DateTimeOffset值的字符串表示形式的日期和时间,通过调用静态字符串分析方法,其中包括许多ParseParseExactTryParse,和TryParseExactYou can also initialize a DateTimeOffset value from the string representation of a date and time by calling a number of static string parsing methods, which include Parse, ParseExact, TryParse, and TryParseExact.

成员DateTimeOffset结构提供以下几个方面的功能:The members of the DateTimeOffset structure provide functionality in the following areas:

  • 日期和时间算术。Date and time arithmetic.

    可以添加或减去的日期或时间间隔从特定DateTimeOffset值。You can add or subtract either dates or time intervals from a particular DateTimeOffset value. 算术运算DateTimeOffset值,与具有不同DateTime时返回的结果值,调整时间偏移量中的差异。Arithmetic operations with DateTimeOffset values, unlike those with DateTime values, adjust for differences in time offsets when returning a result. 例如,下面的代码使用DateTime变量以减去相应的当前本地时间从当前的 UTC 时间。For example, the following code uses DateTime variables to subtract the current local time from the current UTC time. 然后,代码使用DateTimeOffset变量来执行相同的操作。The code then uses DateTimeOffset variables to perform the same operation. 使用减法DateTime值时使用该减法运算返回 UTC,从本地时区的差值DateTimeOffset值返回TimeSpan.ZeroThe subtraction with DateTime values returns the local time zone's difference from UTC, while the subtraction with DateTimeOffset values returns TimeSpan.Zero.

    using System;
    
    public class DateArithmetic
    {
       public static void Main()
       {
          DateTime date1, date2;
          DateTimeOffset dateOffset1, dateOffset2;
          TimeSpan difference;
          
          // Find difference between Date.Now and Date.UtcNow
          date1 = DateTime.Now;
          date2 = DateTime.UtcNow;
          difference = date1 - date2;
          Console.WriteLine("{0} - {1} = {2}", date1, date2, difference);
          
          // Find difference between Now and UtcNow using DateTimeOffset
          dateOffset1 = DateTimeOffset.Now;
          dateOffset2 = DateTimeOffset.UtcNow;
          difference = dateOffset1 - dateOffset2;
          Console.WriteLine("{0} - {1} = {2}", 
                            dateOffset1, dateOffset2, difference);
          // If run in the Pacific Standard time zone on 4/2/2007, the example
          // displays the following output to the console:
          //    4/2/2007 7:23:57 PM - 4/3/2007 2:23:57 AM = -07:00:00
          //    4/2/2007 7:23:57 PM -07:00 - 4/3/2007 2:23:57 AM +00:00 = 00:00:00                        
       }
    }
    
    Module DateArithmetic
       Public Sub Main()
          Dim date1, date2 As Date
          Dim dateOffset1, dateOffset2 As DateTimeOffset
          Dim difference As TimeSpan
          
          ' Find difference between Date.Now and Date.UtcNow
          date1 = Date.Now
          date2 = Date.UtcNow
          difference = date1 - date2
          Console.WriteLine("{0} - {1} = {2}", date1, date2, difference)
          
          ' Find difference between Now and UtcNow using DateTimeOffset
          dateOffset1 = date.Now
          dateOffset2 = date.UtcNow
          difference = dateOffset1 - dateOffset2
          Console.WriteLine("{0} - {1} = {2}", _
                            dateOffset1, dateOffset2, difference)
          ' If run in the Pacific Standard time zone on 4/2/2007, the example
          ' displays the following output to the console:
          '    4/2/2007 7:23:57 PM - 4/3/2007 2:23:57 AM = -07:00:00
          '    4/2/2007 7:23:57 PM -07:00 - 4/3/2007 2:23:57 AM +00:00 = 00:00:00                        
       End Sub
    End Module
    
  • 类型转换操作。Type conversion operations.

    可以将转换DateTimeOffset值到DateTime值,反之亦然。You can convert DateTimeOffset values to DateTime values and vice versa.

  • 时间操作和提取操作。Time manipulation and extraction operations.

    你可以提取日期或时间的DateTimeOffset值。You can extract either the date or the time of a DateTimeOffset value. 此外可以检索特定的值DateTimeOffset组件,例如其年份或月份。You can also retrieve the value of a particular DateTimeOffset component, such as its year or its month.

  • 日期和时间转换。Date and time conversion.

    可以将任何转换DateTimeOffset到另一个值DateTimeOffset值,该值表示在另一个时区的时间相同的点。You can convert any DateTimeOffset value to another DateTimeOffset value that represents the same point in time in another time zone. 但是,仅在的情况下应用时区的调整规则ToLocalTime方法,它将转换DateTimeOffset本地系统区域中的为日期和时间值。However, a time zone's adjustment rules are applied only in the case of the ToLocalTime method, which converts a DateTimeOffset value to the date and time in the local system zone.

  • 日期和时间的比较。Date and time comparison.

    您可以确定是否有任何特定DateTimeOffset值是早于、 等于还是晚于另一个DateTimeOffset值。You can determine whether any particular DateTimeOffset value is earlier than, the same as, or later than another DateTimeOffset value. 在执行比较前,所有值都转换为 UTC。Before the comparison is performed, all values are converted to UTC.

构造函数

DateTimeOffset(DateTime) DateTimeOffset(DateTime) DateTimeOffset(DateTime) DateTimeOffset(DateTime)

使用指定的 DateTime 值初始化 DateTimeOffset 结构的新实例。 Initializes a new instance of the DateTimeOffset structure using the specified DateTime value.

DateTimeOffset(DateTime, TimeSpan) DateTimeOffset(DateTime, TimeSpan) DateTimeOffset(DateTime, TimeSpan) DateTimeOffset(DateTime, TimeSpan)

使用指定的 DateTime 值和偏移量初始化 DateTimeOffset 结构的新实例。 Initializes a new instance of the DateTimeOffset structure using the specified DateTime value and offset.

DateTimeOffset(Int64, TimeSpan) DateTimeOffset(Int64, TimeSpan) DateTimeOffset(Int64, TimeSpan) DateTimeOffset(Int64, TimeSpan)

使用指定的计时周期数和偏移量初始化 DateTimeOffset 结构的新实例。 Initializes a new instance of the DateTimeOffset structure using the specified number of ticks and offset.

DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, TimeSpan) DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, TimeSpan) DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, TimeSpan) DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, TimeSpan)

使用指定的年、月、日、小时、分钟、秒和偏移量初始化 DateTimeOffset 结构的新实例。 Initializes a new instance of the DateTimeOffset structure using the specified year, month, day, hour, minute, second, and offset.

DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, Int32, TimeSpan) DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, Int32, TimeSpan) DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, Int32, TimeSpan) DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, Int32, TimeSpan)

使用指定的年、月、日、小时、分钟、秒、毫秒和偏移量初始化 DateTimeOffset 结构的新实例。 Initializes a new instance of the DateTimeOffset structure using the specified year, month, day, hour, minute, second, millisecond, and offset.

DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar, TimeSpan) DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar, TimeSpan) DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar, TimeSpan) DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar, TimeSpan)

用指定日历的指定年、月、日、小时、分钟、秒、毫秒和偏移量初始化 DateTimeOffset 结构的新实例。 Initializes a new instance of the DateTimeOffset structure using the specified year, month, day, hour, minute, second, millisecond, and offset of a specified calendar.

字段

MaxValue MaxValue MaxValue MaxValue

表示 DateTimeOffset 的最大可能值。 Represents the greatest possible value of DateTimeOffset. 此字段为只读。 This field is read-only.

MinValue MinValue MinValue MinValue

表示可能的最早 DateTimeOffset 值。 Represents the earliest possible DateTimeOffset value. 此字段为只读。 This field is read-only.

UnixEpoch UnixEpoch UnixEpoch UnixEpoch

属性

Date Date Date Date

获取 DateTime 值,该值表示当前 DateTimeOffset 对象的日期组成部分。 Gets a DateTime value that represents the date component of the current DateTimeOffset object.

DateTime DateTime DateTime DateTime

获取 DateTime 值,该值表示当前 DateTimeOffset 对象的日期和时间。 Gets a DateTime value that represents the date and time of the current DateTimeOffset object.

Day Day Day Day

获取由当前 DateTimeOffset 对象所表示的月中的某一天。 Gets the day of the month represented by the current DateTimeOffset object.

DayOfWeek DayOfWeek DayOfWeek DayOfWeek

获取由当前 DateTimeOffset 对象所表示的周中的某一天。 Gets the day of the week represented by the current DateTimeOffset object.

DayOfYear DayOfYear DayOfYear DayOfYear

获取由当前 DateTimeOffset 对象所表示的年中的某一天。 Gets the day of the year represented by the current DateTimeOffset object.

Hour Hour Hour Hour

获取由当前 DateTimeOffset 对象所表示的时间的小时组成部分。 Gets the hour component of the time represented by the current DateTimeOffset object.

LocalDateTime LocalDateTime LocalDateTime LocalDateTime

获取 DateTime 值,该值表示当前 DateTimeOffset 对象的本地日期和时间。 Gets a DateTime value that represents the local date and time of the current DateTimeOffset object.

Millisecond Millisecond Millisecond Millisecond

获取由当前 DateTimeOffset 对象所表示的时间的毫秒组成部分。 Gets the millisecond component of the time represented by the current DateTimeOffset object.

Minute Minute Minute Minute

获取由当前 DateTimeOffset 对象所表示的时间的分钟组成部分。 Gets the minute component of the time represented by the current DateTimeOffset object.

Month Month Month Month

获取由当前 DateTimeOffset 对象所表示的日期的月份组成部分。 Gets the month component of the date represented by the current DateTimeOffset object.

Now Now Now Now

获取一个 DateTimeOffset 对象,该对象设置为当前计算机上的当前日期和时间,偏移量设置为本地时间与协调世界时 (UTC) 之间的偏移量。 Gets a DateTimeOffset object that is set to the current date and time on the current computer, with the offset set to the local time's offset from Coordinated Universal Time (UTC).

Offset Offset Offset Offset

获取与协调世界时 (UTC) 之间的时间偏移量。 Gets the time's offset from Coordinated Universal Time (UTC).

Second Second Second Second

获取由当前 DateTimeOffset 对象所表示的时钟时间的秒组成部分。 Gets the second component of the clock time represented by the current DateTimeOffset object.

Ticks Ticks Ticks Ticks

获取计时周期数,此计时周期数表示时钟时间中当前 DateTimeOffset 对象的日期和时间。 Gets the number of ticks that represents the date and time of the current DateTimeOffset object in clock time.

TimeOfDay TimeOfDay TimeOfDay TimeOfDay

获取当前 DateTimeOffset 对象的日时。 Gets the time of day for the current DateTimeOffset object.

UtcDateTime UtcDateTime UtcDateTime UtcDateTime

获取一个 DateTime 值,该值表示当前 DateTimeOffset 对象的协调世界时 (UTC) 日期和时间。 Gets a DateTime value that represents the Coordinated Universal Time (UTC) date and time of the current DateTimeOffset object.

UtcNow UtcNow UtcNow UtcNow

获取一个 DateTimeOffset 对象,其日期和时间设置为当前的协调世界时 (UTC) 日期和时间,其偏移量为 Zero Gets a DateTimeOffset object whose date and time are set to the current Coordinated Universal Time (UTC) date and time and whose offset is Zero.

UtcTicks UtcTicks UtcTicks UtcTicks

获取表示当前 DateTimeOffset 对象的协调世界时 (UTC) 日期和时间的计时周期数。 Gets the number of ticks that represents the date and time of the current DateTimeOffset object in Coordinated Universal Time (UTC).

Year Year Year Year

获取由当前 DateTimeOffset 对象所表示的日期的年份组成部分。 Gets the year component of the date represented by the current DateTimeOffset object.

方法

Add(TimeSpan) Add(TimeSpan) Add(TimeSpan) Add(TimeSpan)

返回一个新的 DateTimeOffset 对象,它向此实例的值添加指定的时间间隔。 Returns a new DateTimeOffset object that adds a specified time interval to the value of this instance.

AddDays(Double) AddDays(Double) AddDays(Double) AddDays(Double)

返回一个新的 DateTimeOffset 对象,它将由整数和小数部分组成的指定天数加到此实例的值上。 Returns a new DateTimeOffset object that adds a specified number of whole and fractional days to the value of this instance.

AddHours(Double) AddHours(Double) AddHours(Double) AddHours(Double)

返回一个新的 DateTimeOffset 对象,它将由整数和小数部分组成的指定小时数添加到此实例的值上。 Returns a new DateTimeOffset object that adds a specified number of whole and fractional hours to the value of this instance.

AddMilliseconds(Double) AddMilliseconds(Double) AddMilliseconds(Double) AddMilliseconds(Double)

返回一个新的 DateTimeOffset 对象,它将指定的毫秒数加到此实例的值上。 Returns a new DateTimeOffset object that adds a specified number of milliseconds to the value of this instance.

AddMinutes(Double) AddMinutes(Double) AddMinutes(Double) AddMinutes(Double)

返回一个新的 DateTimeOffset 对象,它将由整数和小数部分组成的指定分钟数添加到此实例的值上。 Returns a new DateTimeOffset object that adds a specified number of whole and fractional minutes to the value of this instance.

AddMonths(Int32) AddMonths(Int32) AddMonths(Int32) AddMonths(Int32)

返回一个新的 DateTimeOffset 对象,它将指定的月份数加到此实例的值上。 Returns a new DateTimeOffset object that adds a specified number of months to the value of this instance.

AddSeconds(Double) AddSeconds(Double) AddSeconds(Double) AddSeconds(Double)

返回一个新的 DateTimeOffset 对象,它将由整数和小数部分组成的指定秒数加到此实例的值上。 Returns a new DateTimeOffset object that adds a specified number of whole and fractional seconds to the value of this instance.

AddTicks(Int64) AddTicks(Int64) AddTicks(Int64) AddTicks(Int64)

返回一个新的 DateTimeOffset 对象,它将指定的计时周期数加到此实例的值上。 Returns a new DateTimeOffset object that adds a specified number of ticks to the value of this instance.

AddYears(Int32) AddYears(Int32) AddYears(Int32) AddYears(Int32)

返回一个新的 DateTimeOffset 对象,它将指定的年份数加到此实例的值上。 Returns a new DateTimeOffset object that adds a specified number of years to the value of this instance.

Compare(DateTimeOffset, DateTimeOffset) Compare(DateTimeOffset, DateTimeOffset) Compare(DateTimeOffset, DateTimeOffset) Compare(DateTimeOffset, DateTimeOffset)

对两个 DateTimeOffset 对象进行比较,并指明第一个对象是早于、等于还是晚于第二个对象。 Compares two DateTimeOffset objects and indicates whether the first is earlier than the second, equal to the second, or later than the second.

CompareTo(DateTimeOffset) CompareTo(DateTimeOffset) CompareTo(DateTimeOffset) CompareTo(DateTimeOffset)

将当前的 DateTimeOffset 对象与指定的 DateTimeOffset 对象进行比较,并指明当前对象是早于、等于还是晚于另一个 DateTimeOffset 对象。 Compares the current DateTimeOffset object to a specified DateTimeOffset object and indicates whether the current object is earlier than, the same as, or later than the second DateTimeOffset object.

Equals(DateTimeOffset) Equals(DateTimeOffset) Equals(DateTimeOffset) Equals(DateTimeOffset)

确定当前的 DateTimeOffset 对象是否与指定的 DateTimeOffset 对象表示同一时间点。 Determines whether the current DateTimeOffset object represents the same point in time as a specified DateTimeOffset object.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定 DateTimeOffset 对象是否与指定的对象表示同一时间点。 Determines whether a DateTimeOffset object represents the same point in time as a specified object.

Equals(DateTimeOffset, DateTimeOffset) Equals(DateTimeOffset, DateTimeOffset) Equals(DateTimeOffset, DateTimeOffset) Equals(DateTimeOffset, DateTimeOffset)

确定两个指定的 DateTimeOffset 对象是否表示同一时间点。 Determines whether two specified DateTimeOffset objects represent the same point in time.

EqualsExact(DateTimeOffset) EqualsExact(DateTimeOffset) EqualsExact(DateTimeOffset) EqualsExact(DateTimeOffset)

确定当前的 DateTimeOffset 对象与指定的 DateTimeOffset 对象是否表示同一时间并且是否具有相同的偏移量。 Determines whether the current DateTimeOffset object represents the same time and has the same offset as a specified DateTimeOffset object.

FromFileTime(Int64) FromFileTime(Int64) FromFileTime(Int64) FromFileTime(Int64)

将指定的 Windows 文件时间转换为等效的本地时间。 Converts the specified Windows file time to an equivalent local time.

FromUnixTimeMilliseconds(Int64) FromUnixTimeMilliseconds(Int64) FromUnixTimeMilliseconds(Int64) FromUnixTimeMilliseconds(Int64)

将表示为从 1970-01-01T00:00:00Z 开始已经过的毫秒数的 Unix 时间转换为 DateTimeOffset 值。 Converts a Unix time expressed as the number of milliseconds that have elapsed since 1970-01-01T00:00:00Z to a DateTimeOffset value.

FromUnixTimeSeconds(Int64) FromUnixTimeSeconds(Int64) FromUnixTimeSeconds(Int64) FromUnixTimeSeconds(Int64)

将表示为从 1970-01-01T00:00:00Z 开始已经过的秒数的 Unix 时间转换为 DateTimeOffset 值。 Converts a Unix time expressed as the number of seconds that have elapsed since 1970-01-01T00:00:00Z to a DateTimeOffset value.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

返回当前 DateTimeOffset 对象的哈希代码。 Returns the hash code for the current DateTimeOffset object.

Parse(String) Parse(String) Parse(String) Parse(String)

将日期、时间和偏移量的指定字符串表示形式转换为其等效的 DateTimeOffset Converts the specified string representation of a date, time, and offset to its DateTimeOffset equivalent.

Parse(String, IFormatProvider) Parse(String, IFormatProvider) Parse(String, IFormatProvider) Parse(String, IFormatProvider)

使用指定的区域性特定格式信息,将日期和时间的指定字符串表示形式转换为其等效的 DateTimeOffset Converts the specified string representation of a date and time to its DateTimeOffset equivalent using the specified culture-specific format information.

Parse(ReadOnlySpan<Char>, IFormatProvider, DateTimeStyles) Parse(ReadOnlySpan<Char>, IFormatProvider, DateTimeStyles) Parse(ReadOnlySpan<Char>, IFormatProvider, DateTimeStyles) Parse(ReadOnlySpan<Char>, IFormatProvider, DateTimeStyles)
Parse(String, IFormatProvider, DateTimeStyles) Parse(String, IFormatProvider, DateTimeStyles) Parse(String, IFormatProvider, DateTimeStyles) Parse(String, IFormatProvider, DateTimeStyles)

使用指定的区域性特定格式信息和格式设置样式将日期和时间的指定字符串表示形式转换为其等效的 DateTimeOffset Converts the specified string representation of a date and time to its DateTimeOffset equivalent using the specified culture-specific format information and formatting style.

ParseExact(String, String[], IFormatProvider, DateTimeStyles) ParseExact(String, String[], IFormatProvider, DateTimeStyles) ParseExact(String, String[], IFormatProvider, DateTimeStyles) ParseExact(String, String[], IFormatProvider, DateTimeStyles)

使用指定的格式、区域性特定格式信息和样式将日期和时间的指定字符串表示形式转换为其等效的 DateTimeOffset Converts the specified string representation of a date and time to its DateTimeOffset equivalent using the specified formats, culture-specific format information, and style. 字符串表示形式的格式必须与一种指定的格式完全匹配。 The format of the string representation must match one of the specified formats exactly.

ParseExact(String, String, IFormatProvider, DateTimeStyles) ParseExact(String, String, IFormatProvider, DateTimeStyles) ParseExact(String, String, IFormatProvider, DateTimeStyles) ParseExact(String, String, IFormatProvider, DateTimeStyles)

使用指定的格式、区域性特定的格式信息和样式将日期和时间的指定字符串表示形式转换为其等效的 DateTimeOffset Converts the specified string representation of a date and time to its DateTimeOffset equivalent using the specified format, culture-specific format information, and style. 字符串表示形式的格式必须与指定的格式完全匹配。 The format of the string representation must match the specified format exactly.

ParseExact(ReadOnlySpan<Char>, ReadOnlySpan<Char>, IFormatProvider, DateTimeStyles) ParseExact(ReadOnlySpan<Char>, ReadOnlySpan<Char>, IFormatProvider, DateTimeStyles) ParseExact(ReadOnlySpan<Char>, ReadOnlySpan<Char>, IFormatProvider, DateTimeStyles) ParseExact(ReadOnlySpan<Char>, ReadOnlySpan<Char>, IFormatProvider, DateTimeStyles)

使用指定的格式、区域性特定的格式信息和样式将表示日期和时间的字符范围转换为其等效的 DateTimeOffset Converts a character span that represents a date and time to its DateTimeOffset equivalent using the specified format, culture-specific format information, and style. 日期和时间表示形式的格式必须与指定的格式完全匹配。 The format of the date and time representation must match the specified format exactly.

ParseExact(String, String, IFormatProvider) ParseExact(String, String, IFormatProvider) ParseExact(String, String, IFormatProvider) ParseExact(String, String, IFormatProvider)

使用指定的格式和区域性特定格式信息,将日期和时间的指定字符串表示形式转换为其等效的 DateTimeOffset Converts the specified string representation of a date and time to its DateTimeOffset equivalent using the specified format and culture-specific format information. 字符串表示形式的格式必须与指定的格式完全匹配。 The format of the string representation must match the specified format exactly.

ParseExact(ReadOnlySpan<Char>, String[], IFormatProvider, DateTimeStyles) ParseExact(ReadOnlySpan<Char>, String[], IFormatProvider, DateTimeStyles) ParseExact(ReadOnlySpan<Char>, String[], IFormatProvider, DateTimeStyles) ParseExact(ReadOnlySpan<Char>, String[], IFormatProvider, DateTimeStyles)

使用指定的格式、区域性特定的格式信息和样式将包含日期和时间的字符串表示形式的字符范围转换为其等效的 DateTimeOffset Converts a character span that contains the string representation of a date and time to its DateTimeOffset equivalent using the specified formats, culture-specific format information, and style. 日期和时间表示形式的格式必须与一种指定的格式完全匹配。 The format of the date and time representation must match one of the specified formats exactly.

Subtract(DateTimeOffset) Subtract(DateTimeOffset) Subtract(DateTimeOffset) Subtract(DateTimeOffset)

从当前的 DateTimeOffset 对象中减去表示特定日期和时间的 DateTimeOffset 值。 Subtracts a DateTimeOffset value that represents a specific date and time from the current DateTimeOffset object.

Subtract(TimeSpan) Subtract(TimeSpan) Subtract(TimeSpan) Subtract(TimeSpan)

从当前的 DateTimeOffset 对象中减去指定的时间间隔。 Subtracts a specified time interval from the current DateTimeOffset object.

ToFileTime() ToFileTime() ToFileTime() ToFileTime()

将当前 DateTimeOffset 对象的值转换为 Windows 文件时间。 Converts the value of the current DateTimeOffset object to a Windows file time.

ToLocalTime() ToLocalTime() ToLocalTime() ToLocalTime()

将当前的 DateTimeOffset 对象转换为表示本地时间的 DateTimeOffset 对象。 Converts the current DateTimeOffset object to a DateTimeOffset object that represents the local time.

ToOffset(TimeSpan) ToOffset(TimeSpan) ToOffset(TimeSpan) ToOffset(TimeSpan)

将当前 DateTimeOffset 对象的值转换为偏移量值所指定的日期和时间。 Converts the value of the current DateTimeOffset object to the date and time specified by an offset value.

ToString() ToString() ToString() ToString()

将当前 DateTimeOffset 对象的值转换为其等效的字符串表示形式。 Converts the value of the current DateTimeOffset object to its equivalent string representation.

ToString(IFormatProvider) ToString(IFormatProvider) ToString(IFormatProvider) ToString(IFormatProvider)

使用指定的区域性特定格式设置信息将当前 DateTimeOffset 对象的值转换为它的等效字符串表示形式。 Converts the value of the current DateTimeOffset object to its equivalent string representation using the specified culture-specific formatting information.

ToString(String) ToString(String) ToString(String) ToString(String)

使用指定的格式将当前 DateTimeOffset 对象的值转换为它的等效字符串表示形式。 Converts the value of the current DateTimeOffset object to its equivalent string representation using the specified format.

ToString(String, IFormatProvider) ToString(String, IFormatProvider) ToString(String, IFormatProvider) ToString(String, IFormatProvider)

使用指定的格式和区域性特定格式信息将当前 DateTimeOffset 对象的值转换为它的等效字符串表示形式。 Converts the value of the current DateTimeOffset object to its equivalent string representation using the specified format and culture-specific format information.

ToUniversalTime() ToUniversalTime() ToUniversalTime() ToUniversalTime()

将当前的 DateTimeOffset 对象转换为一个表示协调世界时 (UTC) 的 DateTimeOffset 值。 Converts the current DateTimeOffset object to a DateTimeOffset value that represents the Coordinated Universal Time (UTC).

ToUnixTimeMilliseconds() ToUnixTimeMilliseconds() ToUnixTimeMilliseconds() ToUnixTimeMilliseconds()

返回自 1970-01-01T00:00:00.000Z 起已经过的毫秒数。 Returns the number of milliseconds that have elapsed since 1970-01-01T00:00:00.000Z.

ToUnixTimeSeconds() ToUnixTimeSeconds() ToUnixTimeSeconds() ToUnixTimeSeconds()

返回自 1970-01-01T00:00:00.00Z 起已经过的秒数。 Returns the number of seconds that have elapsed since 1970-01-01T00:00:00Z.

TryFormat(Span<Char>, Int32, ReadOnlySpan<Char>, IFormatProvider) TryFormat(Span<Char>, Int32, ReadOnlySpan<Char>, IFormatProvider) TryFormat(Span<Char>, Int32, ReadOnlySpan<Char>, IFormatProvider) TryFormat(Span<Char>, Int32, ReadOnlySpan<Char>, IFormatProvider)
TryParse(String, IFormatProvider, DateTimeStyles, DateTimeOffset) TryParse(String, IFormatProvider, DateTimeStyles, DateTimeOffset) TryParse(String, IFormatProvider, DateTimeStyles, DateTimeOffset) TryParse(String, IFormatProvider, DateTimeStyles, DateTimeOffset)

尝试将日期和时间的指定字符串表示形式转换为它的等效 DateTimeOffset,并返回一个指示转换是否成功的值。 Tries to convert a specified string representation of a date and time to its DateTimeOffset equivalent, and returns a value that indicates whether the conversion succeeded.

TryParse(ReadOnlySpan<Char>, IFormatProvider, DateTimeStyles, DateTimeOffset) TryParse(ReadOnlySpan<Char>, IFormatProvider, DateTimeStyles, DateTimeOffset) TryParse(ReadOnlySpan<Char>, IFormatProvider, DateTimeStyles, DateTimeOffset) TryParse(ReadOnlySpan<Char>, IFormatProvider, DateTimeStyles, DateTimeOffset)
TryParse(String, DateTimeOffset) TryParse(String, DateTimeOffset) TryParse(String, DateTimeOffset) TryParse(String, DateTimeOffset)

尝试将日期和时间的指定字符串表示形式转换为它的等效 DateTimeOffset,并返回一个指示转换是否成功的值。 Tries to converts a specified string representation of a date and time to its DateTimeOffset equivalent, and returns a value that indicates whether the conversion succeeded.

TryParse(ReadOnlySpan<Char>, DateTimeOffset) TryParse(ReadOnlySpan<Char>, DateTimeOffset) TryParse(ReadOnlySpan<Char>, DateTimeOffset) TryParse(ReadOnlySpan<Char>, DateTimeOffset)
TryParseExact(String, String[], IFormatProvider, DateTimeStyles, DateTimeOffset) TryParseExact(String, String[], IFormatProvider, DateTimeStyles, DateTimeOffset) TryParseExact(String, String[], IFormatProvider, DateTimeStyles, DateTimeOffset) TryParseExact(String, String[], IFormatProvider, DateTimeStyles, DateTimeOffset)

使用指定的格式数组、区域性特定格式信息和样式,将日期和时间的指定字符串表示形式转换为其等效的 DateTimeOffset Converts the specified string representation of a date and time to its DateTimeOffset equivalent using the specified array of formats, culture-specific format information, and style. 字符串表示形式的格式必须与一种指定的格式完全匹配。 The format of the string representation must match one of the specified formats exactly.

TryParseExact(ReadOnlySpan<Char>, ReadOnlySpan<Char>, IFormatProvider, DateTimeStyles, DateTimeOffset) TryParseExact(ReadOnlySpan<Char>, ReadOnlySpan<Char>, IFormatProvider, DateTimeStyles, DateTimeOffset) TryParseExact(ReadOnlySpan<Char>, ReadOnlySpan<Char>, IFormatProvider, DateTimeStyles, DateTimeOffset) TryParseExact(ReadOnlySpan<Char>, ReadOnlySpan<Char>, IFormatProvider, DateTimeStyles, DateTimeOffset)

使用指定的格式、区域性特定的格式信息和样式将字符范围中的日期和时间的表示形式转换为其等效的 DateTimeOffset Converts the representation of a date and time in a character span to its DateTimeOffset equivalent using the specified format, culture-specific format information, and style. 日期和时间表示形式的格式必须与指定的格式完全匹配。 The format of the date and time representation must match the specied format exactly.

TryParseExact(ReadOnlySpan<Char>, String[], IFormatProvider, DateTimeStyles, DateTimeOffset) TryParseExact(ReadOnlySpan<Char>, String[], IFormatProvider, DateTimeStyles, DateTimeOffset) TryParseExact(ReadOnlySpan<Char>, String[], IFormatProvider, DateTimeStyles, DateTimeOffset) TryParseExact(ReadOnlySpan<Char>, String[], IFormatProvider, DateTimeStyles, DateTimeOffset)
TryParseExact(String, String, IFormatProvider, DateTimeStyles, DateTimeOffset) TryParseExact(String, String, IFormatProvider, DateTimeStyles, DateTimeOffset) TryParseExact(String, String, IFormatProvider, DateTimeStyles, DateTimeOffset) TryParseExact(String, String, IFormatProvider, DateTimeStyles, DateTimeOffset)

使用指定的格式、区域性特定的格式信息和样式将日期和时间的指定字符串表示形式转换为其等效的 DateTimeOffset Converts the specified string representation of a date and time to its DateTimeOffset equivalent using the specified format, culture-specific format information, and style. 字符串表示形式的格式必须与指定的格式完全匹配。 The format of the string representation must match the specified format exactly.

操作员

Addition(DateTimeOffset, TimeSpan) Addition(DateTimeOffset, TimeSpan) Addition(DateTimeOffset, TimeSpan) Addition(DateTimeOffset, TimeSpan)

将指定的时间间隔与具有指定的日期和时间的 DateTimeOffset 对象相加,产生一个具有新的日期和时间的 DateTimeOffset 对象。 Adds a specified time interval to a DateTimeOffset object that has a specified date and time, and yields a DateTimeOffset object that has new a date and time.

Equality(DateTimeOffset, DateTimeOffset) Equality(DateTimeOffset, DateTimeOffset) Equality(DateTimeOffset, DateTimeOffset) Equality(DateTimeOffset, DateTimeOffset)

确定两个指定的 DateTimeOffset 对象是否表示同一时间点。 Determines whether two specified DateTimeOffset objects represent the same point in time.

GreaterThan(DateTimeOffset, DateTimeOffset) GreaterThan(DateTimeOffset, DateTimeOffset) GreaterThan(DateTimeOffset, DateTimeOffset) GreaterThan(DateTimeOffset, DateTimeOffset)

确定一个指定的 DateTimeOffset 对象是否大于(或晚于)另一个指定的 DateTimeOffset 对象。 Determines whether one specified DateTimeOffset object is greater than (or later than) a second specified DateTimeOffset object.

GreaterThanOrEqual(DateTimeOffset, DateTimeOffset) GreaterThanOrEqual(DateTimeOffset, DateTimeOffset) GreaterThanOrEqual(DateTimeOffset, DateTimeOffset) GreaterThanOrEqual(DateTimeOffset, DateTimeOffset)

确定一个指定的 DateTimeOffset 对象是大于还是等于另一个指定的 DateTimeOffset 对象。 Determines whether one specified DateTimeOffset object is greater than or equal to a second specified DateTimeOffset object.

Implicit(DateTime to DateTimeOffset) Implicit(DateTime to DateTimeOffset) Implicit(DateTime to DateTimeOffset) Implicit(DateTime to DateTimeOffset)

定义从 DateTime 对象到 DateTimeOffset 对象的隐式转换。 Defines an implicit conversion of a DateTime object to a DateTimeOffset object.

Inequality(DateTimeOffset, DateTimeOffset) Inequality(DateTimeOffset, DateTimeOffset) Inequality(DateTimeOffset, DateTimeOffset) Inequality(DateTimeOffset, DateTimeOffset)

确定两个指定的 DateTimeOffset 对象是否表示不同的时间点。 Determines whether two specified DateTimeOffset objects refer to different points in time.

LessThan(DateTimeOffset, DateTimeOffset) LessThan(DateTimeOffset, DateTimeOffset) LessThan(DateTimeOffset, DateTimeOffset) LessThan(DateTimeOffset, DateTimeOffset)

确定一个指定的 DateTimeOffset 对象是否小于另一个指定的 DateTimeOffset 对象。 Determines whether one specified DateTimeOffset object is less than a second specified DateTimeOffset object.

LessThanOrEqual(DateTimeOffset, DateTimeOffset) LessThanOrEqual(DateTimeOffset, DateTimeOffset) LessThanOrEqual(DateTimeOffset, DateTimeOffset) LessThanOrEqual(DateTimeOffset, DateTimeOffset)

确定一个指定的 DateTimeOffset 对象是否小于另一个指定的 DateTimeOffset 对象。 Determines whether one specified DateTimeOffset object is less than a second specified DateTimeOffset object.

Subtraction(DateTimeOffset, DateTimeOffset) Subtraction(DateTimeOffset, DateTimeOffset) Subtraction(DateTimeOffset, DateTimeOffset) Subtraction(DateTimeOffset, DateTimeOffset)

从一个 DateTimeOffset 对象中减去另一个对象并生成时间间隔。 Subtracts one DateTimeOffset object from another and yields a time interval.

Subtraction(DateTimeOffset, TimeSpan) Subtraction(DateTimeOffset, TimeSpan) Subtraction(DateTimeOffset, TimeSpan) Subtraction(DateTimeOffset, TimeSpan)

从指定的日期和时间减去指定的时间间隔,并生成新的日期和时间。 Subtracts a specified time interval from a specified date and time, and yields a new date and time.

显式界面实现

IComparable.CompareTo(Object) IComparable.CompareTo(Object) IComparable.CompareTo(Object) IComparable.CompareTo(Object)

将当前 DateTimeOffset 对象的值与相同类型的另一个对象进行比较。 Compares the value of the current DateTimeOffset object with another object of the same type.

IDeserializationCallback.OnDeserialization(Object) IDeserializationCallback.OnDeserialization(Object) IDeserializationCallback.OnDeserialization(Object) IDeserializationCallback.OnDeserialization(Object)

在对象的反序列化完成时运行。 Runs when the deserialization of an object has been completed.

ISerializable.GetObjectData(SerializationInfo, StreamingContext) ISerializable.GetObjectData(SerializationInfo, StreamingContext) ISerializable.GetObjectData(SerializationInfo, StreamingContext) ISerializable.GetObjectData(SerializationInfo, StreamingContext)

使用序列化当前 SerializationInfo 对象所需的数据来填充 DateTimeOffset 对象。 Populates a SerializationInfo object with the data required to serialize the current DateTimeOffset object.

适用于

另请参阅