DateTimeOffset 結構

定義

表示一個時間點,通常以一天的日期和時間表示 (相對於國際標準時間)。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
public value class DateTimeOffset : IComparable, IComparable<DateTimeOffset>, IEquatable<DateTimeOffset>, IFormattable, System::Runtime::Serialization::IDeserializationCallback, System::Runtime::Serialization::ISerializable
public struct DateTimeOffset : IComparable, IComparable<DateTimeOffset>, IEquatable<DateTimeOffset>, IFormattable
public struct 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
type DateTimeOffset = struct
    interface IFormattable
    interface IDeserializationCallback
    interface ISerializable
[<System.Serializable>]
type DateTimeOffset = struct
    interface IFormattable
    interface ISerializable
    interface IDeserializationCallback
Public Structure DateTimeOffset
Implements IComparable, IComparable(Of DateTimeOffset), IEquatable(Of DateTimeOffset), IFormattable
Public Structure DateTimeOffset
Implements IComparable, IComparable(Of DateTimeOffset), IDeserializationCallback, IEquatable(Of DateTimeOffset), IFormattable, ISerializable
繼承
DateTimeOffset
屬性
實作

備註

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 午夜午夜(0001年1月1日午夜)西元西元 () 年12月31日下午11:59:59,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.).

重要

日本曆法的紀元是以天皇的統治為基礎,因此有變更是正常的。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 系統上測試您的應用程式,確保其已準備好面對紀元變更,請參閱 Prepare your application for the Japanese era change (讓應用程式準備好因應日本紀元變更)。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 值,這類似于結構的多載的函式 DateTimeYou 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. 您也可以指派值給它,以建立新的 DateTimeOffsetDateTimeYou 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 呼叫一些靜態字串剖析方法(包括、、和),將值從日期和時間的字串表示初始化 Parse ParseExact TryParse 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.

    您可以新增或減去特定值的日期或時間間隔 DateTimeOffsetYou 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.

    您可以解壓縮日期或值的時間 DateTimeOffsetYou 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.TicksPerDay 、、 TimeSpan.TicksPerHour TimeSpan.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)

使用指定的 DateTime 值,初始化 DateTimeOffset 結構的新執行個體。Initializes a new instance of the DateTimeOffset structure using the specified DateTime value.

DateTimeOffset(DateTime, TimeSpan)

使用指定的 DateTime 值及位移,初始化 DateTimeOffset 結構的新執行個體。Initializes a new instance of the DateTimeOffset structure using the specified DateTime value and offset.

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.

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, TimeSpan)

使用指定的年、月、日、時、分、秒和位移,初始化 DateTimeOffset 結構的新執行個體。Initializes a new instance of the DateTimeOffset structure using the specified year, month, day, hour, minute, second, and offset.

DateTimeOffset(Int64, TimeSpan)

使用指定數目的刻度和位移,初始化 DateTimeOffset 結構的新執行個體。Initializes a new instance of the DateTimeOffset structure using the specified number of ticks and offset.

欄位

MaxValue

表示 DateTimeOffset 的最大可能值。Represents the greatest possible value of DateTimeOffset. 此欄位為唯讀。This field is read-only.

MinValue

表示最早的 DateTimeOffset 可能值。Represents the earliest possible DateTimeOffset value. 此欄位為唯讀。This field is read-only.

UnixEpoch

這個常數的值相當於西曆中的國際標準時間 00:00:00.0000000,1970 年 1 月 1 日。The value of this constant is equivalent to 00:00:00.0000000 UTC, January 1, 1970, in the Gregorian calendar. UnixEpoch 定義 UNIX 時間等於 0 的時間點。UnixEpoch defines the point in time when Unix time is equal to 0.

屬性

Date

取得 DateTime 值,這個值表示目前 DateTimeOffset 物件的日期元件。Gets a DateTime value that represents the date component of the current DateTimeOffset object.

DateTime

取得 DateTime 值,這個值表示目前 DateTimeOffset 物件的日期和時間。Gets a DateTime value that represents the date and time of the current DateTimeOffset object.

Day

取得由目前 DateTimeOffset 物件所表示之月份中的第幾天。Gets the day of the month represented by the current DateTimeOffset object.

DayOfWeek

取得由目前 DateTimeOffset 物件所表示的星期幾。Gets the day of the week represented by the current DateTimeOffset object.

DayOfYear

取得由目前 DateTimeOffset 物件所表示之一年中的第幾天。Gets the day of the year represented by the current DateTimeOffset object.

Hour

取得目前 DateTimeOffset 物件表示之時間的時數元件。Gets the hour component of the time represented by the current DateTimeOffset object.

LocalDateTime

取得 DateTime 值,這個值表示目前 DateTimeOffset 物件的本地日期和時間。Gets a DateTime value that represents the local date and time of the current DateTimeOffset object.

Millisecond

取得目前 DateTimeOffset 物件所表示之時間的毫秒數元件。Gets the millisecond component of the time represented by the current DateTimeOffset object.

Minute

取得目前 DateTimeOffset 物件所表示之時間的分鐘數元件。Gets the minute component of the time represented by the current DateTimeOffset object.

Month

取得目前 DateTimeOffset 物件所表示之日期的月份元件。Gets the month component of the date represented by the current DateTimeOffset object.

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

取得 Coordinated Universal Time (UTC) 的時間位移。Gets the time's offset from Coordinated Universal Time (UTC).

Second

取得目前 DateTimeOffset 物件所表示之時鐘時間的秒數元件。Gets the second component of the clock time represented by the current DateTimeOffset object.

Ticks

取得刻度數,這個值表示目前 DateTimeOffset 物件之時鐘時間的日期和時間。Gets the number of ticks that represents the date and time of the current DateTimeOffset object in clock time.

TimeOfDay

取得目前 DateTimeOffset 物件之一天中的時間。Gets the time of day for the current DateTimeOffset object.

UtcDateTime

取得 DateTime 值,這個值表示目前 DateTimeOffset 物件的 Coordinated Universal Time (UTC) 日期和時間。Gets a DateTime value that represents the Coordinated Universal Time (UTC) date and time of the current DateTimeOffset object.

UtcNow

取得 DateTimeOffset 物件,這個物件的日期和時間已設定為目前 Coordinated Universal Time (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

取得刻度數,這個值表示目前 DateTimeOffset 物件之 Coordinated Universal Time (UTC) 的日期和時間。Gets the number of ticks that represents the date and time of the current DateTimeOffset object in Coordinated Universal Time (UTC).

Year

取得目前 DateTimeOffset 物件所表示之日期的年份元件。Gets the year component of the date represented by the current DateTimeOffset object.

方法

Add(TimeSpan)

傳回新的 DateTimeOffset 物件,將這個執行個體的值加上指定的時間間隔。Returns a new DateTimeOffset object that adds a specified time interval to the value of this instance.

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)

傳回新的 DateTimeOffset 物件,這個物件將這個執行個體的值加上指定的整數和小數時數。Returns a new DateTimeOffset object that adds a specified number of whole and fractional hours to the value of this instance.

AddMilliseconds(Double)

傳回新的 DateTimeOffset 物件,將這個執行個體的值加上指定的毫秒數。Returns a new DateTimeOffset object that adds a specified number of milliseconds to the value of this instance.

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)

傳回新的 DateTimeOffset 物件,將這個執行個體的值加上指定的月數。Returns a new DateTimeOffset object that adds a specified number of months to the value of this instance.

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)

傳回新的 DateTimeOffset 物件,將這個執行個體的值加上指定的刻度數。Returns a new DateTimeOffset object that adds a specified number of ticks to the value of this instance.

AddYears(Int32)

傳回新的 DateTimeOffset 物件,將這個執行個體的值加上指定的年數。Returns a new DateTimeOffset object that adds a specified number of years to the value of this instance.

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)

將目前 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)

判斷目前 DateTimeOffset 物件與指定的 DateTimeOffset 物件是否代表相同的時間點。Determines whether the current DateTimeOffset object represents the same point in time as a specified DateTimeOffset object.

Equals(DateTimeOffset, DateTimeOffset)

判斷兩個指定的 DateTimeOffset 物件是否代表相同的時間點。Determines whether two specified DateTimeOffset objects represent the same point in time.

Equals(Object)

判斷 DateTimeOffset 物件與指定的物件是否代表相同的時間點。Determines whether a DateTimeOffset object represents the same point in time as a specified object.

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)

將指定的 Windows 檔案時間轉換成相等的本地時間。Converts the specified Windows file time to an equivalent local time.

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)

將自 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()

傳回目前 DateTimeOffset 物件的雜湊碼。Returns the hash code for the current DateTimeOffset object.

Parse(ReadOnlySpan<Char>, IFormatProvider, DateTimeStyles)

使用指定的特定文化特性格式資訊和格式樣式,將日期和時間的指定範圍表示轉換為其對等的 DateTimeOffsetConverts the specified span representation of a date and time to its DateTimeOffset equivalent using the specified culture-specific format information and formatting style.

Parse(String)

將日期、時間和位移的指定字串表示,轉換為其相等的 DateTimeOffsetConverts the specified string representation of a date, time, and offset to its DateTimeOffset equivalent.

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(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(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(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.

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(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(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.

Subtract(DateTimeOffset)

從目前的 DateTimeOffset 物件減去表示特定日期和時間的 DateTimeOffset 值。Subtracts a DateTimeOffset value that represents a specific date and time from the current DateTimeOffset object.

Subtract(TimeSpan)

從目前 DateTimeOffset 物件減去指定的時間間隔。Subtracts a specified time interval from the current DateTimeOffset object.

ToFileTime()

將目前 DateTimeOffset 物件的值轉換成 Windows 檔案時間。Converts the value of the current DateTimeOffset object to a Windows file time.

ToLocalTime()

將目前 DateTimeOffset 物件轉換為表示本地時間的 DateTimeOffset 物件。Converts the current DateTimeOffset object to a DateTimeOffset object that represents the local time.

ToOffset(TimeSpan)

將目前 DateTimeOffset 物件的值轉換為位移值指定的日期和時間。Converts the value of the current DateTimeOffset object to the date and time specified by an offset value.

ToString()

將目前 DateTimeOffset 物件的值,轉換為其相等的字串表示。Converts the value of the current DateTimeOffset object to its equivalent string representation.

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)

使用指定的格式,將目前 DateTimeOffset 物件的值,轉換為其相等字串表示。Converts the value of the current DateTimeOffset object to its equivalent string representation using the specified format.

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()

將目前 DateTimeOffset 物件轉換為表示 Coordinated Universal Time (UTC) 的 DateTimeOffset 值。Converts the current DateTimeOffset object to a DateTimeOffset value that represents the Coordinated Universal Time (UTC).

ToUnixTimeMilliseconds()

傳回自 1970-01-01T00:00:00.000Z 以來所經過的毫秒數。Returns the number of milliseconds that have elapsed since 1970-01-01T00:00:00.000Z.

ToUnixTimeSeconds()

傳回自 1970-01-01T00:00:00Z 以來所經過的秒數。Returns the number of seconds that have elapsed since 1970-01-01T00:00:00Z.

TryFormat(Span<Char>, Int32, ReadOnlySpan<Char>, IFormatProvider)

嘗試將目前日期時間位移執行個體的值格式化為所提供的字元範圍。Tries to format the value of the current datetime offset instance into the provided span of characters.

TryParse(ReadOnlySpan<Char>, DateTimeOffset)

嘗試將日期和時間的指定範圍表示轉換為其對等的 DateTimeOffset,並傳回值以指出轉換是否成功。Tries to convert a specified span 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)

嘗試將日期和時間的指定範圍表示轉換為其對等的 DateTimeOffset,並傳回值以指出轉換是否成功。Tries to convert a specified span representation of a date and time to its DateTimeOffset equivalent, and returns a value that indicates whether the conversion succeeded.

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(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.

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)

使用指定的格式、特定的文化特性格式資訊及樣式,將字元範圍中的日期和時間表示轉換為其對等的 DateTimeOffsetConverts the representation of a date and time in a character span 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.

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.

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.

運算子

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)

判斷兩個指定的 DateTimeOffset 物件是否代表相同的時間點。Determines whether two specified DateTimeOffset objects represent the same point in time.

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)

判斷一個指定的 DateTimeOffset 物件是否大於 (或等於) 第二個指定的 DateTimeOffset 物件。Determines whether one specified DateTimeOffset object is greater than or equal to a second specified DateTimeOffset object.

Implicit(DateTime to DateTimeOffset)

定義從 DateTime 物件到 DateTimeOffset 物件的隱含轉換。Defines an implicit conversion of a DateTime object to a DateTimeOffset object.

Inequality(DateTimeOffset, DateTimeOffset)

判斷兩個指定的 DateTimeOffset 物件是否參照不同的時間點。Determines whether two specified DateTimeOffset objects refer to different points in time.

LessThan(DateTimeOffset, DateTimeOffset)

判斷一個指定的 DateTimeOffset 物件是否小於第二個指定的 DateTimeOffset 物件。Determines whether one specified DateTimeOffset object is less than a second specified DateTimeOffset object.

LessThanOrEqual(DateTimeOffset, DateTimeOffset)

判斷一個指定的 DateTimeOffset 物件是否小於第二個指定的 DateTimeOffset 物件。Determines whether one specified DateTimeOffset object is less than a second specified DateTimeOffset object.

Subtraction(DateTimeOffset, DateTimeOffset)

從其他 DateTimeOffset 物件減去一個物件並產生時間間隔。Subtracts one DateTimeOffset object from another and yields a time interval.

Subtraction(DateTimeOffset, TimeSpan)

從指定的日期和時間減去指定的時間間隔,並產生新的日期和時間。Subtracts a specified time interval from a specified date and time, and yields a new date and time.

明確介面實作

IComparable.CompareTo(Object)

比較目前 DateTimeOffset 物件與同類型之另一個物件的值。Compares the value of the current DateTimeOffset object with another object of the same type.

IDeserializationCallback.OnDeserialization(Object)

在物件完成還原序列化時執行。Runs when the deserialization of an object has been completed.

ISerializable.GetObjectData(SerializationInfo, StreamingContext)

將序列化目前 SerializationInfo 物件所需的資料填入 DateTimeOffset 物件。Populates a SerializationInfo object with the data required to serialize the current DateTimeOffset object.

適用於

另請參閱