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, 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
繼承
DateTimeOffset
屬性
實作

備註

結構包含一個DateTime 值,以及定義DateTimeOffset目前實例日期和時間與國際標準時間(UTC)之間差異的屬性。Offset 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 年1月1日午夜(西元西元(Common 紀元))到11:59:59 年12月31日下午2點,9999It 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其任何一個函式的多載(類似于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呼叫靜態字串剖析方法的數目(包括ParseParseExactTryParseTryParseExact),從日期和時間的字串表示初始化值。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 的差異,而與DateTimeOffsetTimeSpan.Zero的減法則會傳回。The 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.TicksPerMinute TimeSpan.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)

使用指定的 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

屬性

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)
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)
TryParse(ReadOnlySpan<Char>, DateTimeOffset)
TryParse(ReadOnlySpan<Char>, IFormatProvider, DateTimeStyles, 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(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)
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.

適用於

另請參閱