DateTimeOffset DateTimeOffset DateTimeOffset DateTimeOffset Struct

定義

表示一個時間點,通常以一天的日期和時間表示 (相對於國際標準時間)。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
屬性
實作

備註

DateTimeOffset結構包含DateTime值,連同Offset屬性,定義目前差異DateTimeOffset執行個體的日期和時間和 Coordinated Universal Time (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. 它代表下午 11:59:59,年 12 月 31 到西元 9999年日的日期和時間的 UTC 範圍 12:00:00,年 1 月 1 日午夜 0001 P.m (中古時代) 的值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.).

重要

日本曆法的紀元是以天皇的統治為基礎,因此有變更是正常的。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.

時間元件的DateTimeOffset100 奈秒為單位,稱為次滴答聲,則會測量值,且在特定日期的刻度數午夜 12:00,年 1 月 1,西元 0001年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. ADateTimeOffset值一律表示在內容明確或預設的行事曆。A DateTimeOffset value is always expressed in the context of an explicit or default calendar. 為能歸因於 leap 秒為單位的刻度未被納入的滴答總數。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值的字串表示的日期和時間,藉由呼叫靜態字串剖析方法,其包括許多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.

注意

如果您正在使用刻度值,您想要轉換成某些其他時間間隔,例如分鐘或秒,您應該使用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.

  • 日期和時間轉換。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

表示最大的可能值的DateTimeOffsetRepresents 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

與 Coordinated Universal Time (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值,表示 Coordinated Universal Time (UTC) 日期和時間的目前DateTimeOffset物件。Gets a DateTime value that represents the Coordinated Universal Time (UTC) date and time of the current DateTimeOffset object.

UtcNow UtcNow UtcNow 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 UtcTicks UtcTicks 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 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物件至DateTimeOffset表示 Coordinated Universal Time (UTC) 值。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: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.

適用於

另請參閱