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
[System.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
属性
实现

注解

结构包含一个DateTime值和一个Offset属性,该属性定义当前DateTimeOffset实例的日期和时间与协调世界时(UTC)之间的差异。 DateTimeOffsetThe 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 午夜,0001年1月1日午夜,到 11:59:59 P.M,年12月31日,9999公元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.).

重要

日本历法中的年号是根据天皇统治来命名的,因此预计会发生变化。Eras in the Japanese calendars are based on the emperor's reign and are therefore expected to change. 例如,2019 年 5 月 1 日在 JapaneseCalendarJapaneseLunisolarCalendar 中标志着令和年号的开始。For example, May 1, 2019 marked the beginning of the Reiwa era in the JapaneseCalendar and JapaneseLunisolarCalendar. 这种年号的变化会影响使用这些日历的所有应用程序。Such a change of era affects all applications that use these calendars. 请参阅 Handling a new era in the Japanese calendar in .NET(使用 .NET 处理日语日历中的新元号),了解详细信息并确定是否会影响你的应用程序。See Handling a new era in the Japanese calendar in .NET for more information and to determine whether your applications are affected. 请参阅针对日语元号更改准备应用程序,了解有关在 Windows 系统上测试应用程序以确保针对元号更改的准备情况信息。See Prepare your application for the Japanese era change for information on testing your applications on Windows systems to ensure their readiness for the era change. 有关 .Net 中支持多个年号日历的功能,以及在使用支持多个年号的日历时的最佳做法,请参阅使用年号See Working with eras for features in .NET that support calendars with multiple eras and for best practices when working with calendars that support multiple eras.

DateTimeOffset值的时间部分以100毫微秒为单位进行度量,其中,特定日期为自公元0001年1月1日午夜12:00 午夜后的计时周期数。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. 公元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.

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静态字符串分析方法(包括ParseParseExact TryParse、和TryParseExact),从日期和时间的字符串表示形式初始化值。You 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.

备注

如果使用的计时周期值要转换为其他时间间隔(如分钟或秒),则应使用TimeSpan.TicksPerDayTimeSpan.TicksPerHourTimeSpan.TicksPerMinuteTimeSpan.TicksPerSecondTimeSpan.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.

  • 日期和时间转换。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) 日期和时间,其偏移量为 ZeroGets 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)

将日期、时间和偏移量的指定字符串表示形式转换为其等效的 DateTimeOffsetConverts 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)

使用指定的特定于区域性的格式信息,将日期和时间的指定字符串表示形式转换为其等效的 DateTimeOffsetConverts 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)

使用指定的区域性特定格式信息和格式设置样式将日期和时间的指定字符串表示形式转换为其等效的 DateTimeOffsetConverts 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)

使用指定的格式、区域性特定的格式信息和样式将日期和时间的指定字符串表示形式转换为其等效的 DateTimeOffsetConverts 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)

使用指定的格式、区域性特定的格式信息和样式将日期和时间的指定字符串表示形式转换为其等效的 DateTimeOffsetConverts 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)

使用指定的格式、区域性特定的格式信息和样式将表示日期和时间的字符范围转换为其等效的 DateTimeOffsetConverts 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)

使用指定的格式和区域性特定格式信息,将日期和时间的指定字符串表示形式转换为其等效的 DateTimeOffsetConverts 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)

使用指定的格式、区域性特定的格式信息和样式将包含日期和时间的字符串表示形式的字符范围转换为其等效的 DateTimeOffsetConverts 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)

使用指定的格式数组、区域性特定格式信息和样式,将日期和时间的指定字符串表示形式转换为其等效的 DateTimeOffsetConverts 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)

使用指定的格式、区域性特定的格式信息和样式将字符范围中的日期和时间的表示形式转换为其等效的 DateTimeOffsetConverts 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 specified 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)

使用指定的格式、区域性特定的格式信息和样式将日期和时间的指定字符串表示形式转换为其等效的 DateTimeOffsetConverts 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.

适用于

另请参阅