Early Preview
This is currently very much a preview. Please feel free to try things out,
but don't be upset if anything is not yet working. Feedback is welcome over on our
GitHub Dicussions page.
struct NodaTime.​OffsetDateTime
Assembly: NodaTime
Implemented Interfaces
- System.​IEquatable`1
- System.​IFormattable
- System.​Xml.​Serialization.​IXmlSerializable
- System.​Numerics.​IAdditionOperators`3
- System.​Numerics.​ISubtractionOperators`3
- System.​Numerics.​IEqualityOperators`3
A local date and time in a particular calendar system, combined with an offset from UTC. This is broadly similar to <see cref="T:System.DateTimeOffset" /> in the BCL.
Remarks
<para>
Equality is defined in a component-wise fashion: two values are the same if they represent equal date/time values
(including being in the same calendar) and equal offsets from UTC.
Ordering between offset date/time values has no natural definition; see <see cref="T:NodaTime.OffsetDateTime.Comparer" /> for built-in comparers.
</para> <para>
A value of this type unambiguously represents both a local time and an instant on the timeline,
but does not have a well-defined time zone. This means you cannot reliably know what the local
time would be five minutes later, for example. While this doesn't sound terribly useful, it's very common
in text representations.
</para> <para>The default value of this type is 0001-01-01T00:00:00Z (midnight on January 1st, 1 C.E. with a UTC offset of 0) in the ISO calendar.</para>
Properties
public
CalendarSystem
Calendar
Gets the calendar system associated with this offset date and time.
public
int
Year
Gets the year of this offset date and time.
Remarks This returns the "absolute year", so, for the ISO calendar,
a value of 0 means 1 BC, for example.
public
int
Month
Gets the month of this offset date and time within the year.
public
int
Day
Gets the day of this offset date and time within the month.
public
IsoDayOfWeek
DayOfWeek
Gets the week day of this offset date and time expressed as an <see cref="T:NodaTime.IsoDayOfWeek" /> value.
public
int
YearOfEra
Gets the year of this offset date and time within the era.
public
Era
Era
Gets the era of this offset date and time.
public
int
DayOfYear
Gets the day of this offset date and time within the year.
public
int
Hour
Gets the hour of day of this offset date and time, in the range 0 to 23 inclusive.
public
int
ClockHourOfHalfDay
Gets the hour of the half-day of this offset date and time, in the range 1 to 12 inclusive.
public
int
Minute
Gets the minute of this offset date and time, in the range 0 to 59 inclusive.
public
int
Second
Gets the second of this offset date and time within the minute, in the range 0 to 59 inclusive.
public
int
Millisecond
Gets the millisecond of this offset date and time within the second, in the range 0 to 999 inclusive.
public
int
TickOfSecond
Gets the tick of this offset date and time within the second, in the range 0 to 9,999,999 inclusive.
public
long
TickOfDay
Gets the tick of this offset date and time within the day, in the range 0 to 863,999,999,999 inclusive.
public
int
NanosecondOfSecond
Gets the nanosecond of this offset date and time within the second, in the range 0 to 999,999,999 inclusive.
public
long
NanosecondOfDay
Gets the nanosecond of this offset date and time within the day, in the range 0 to 86,399,999,999,999 inclusive.
public
LocalDateTime
LocalDateTime
Returns the local date and time represented within this offset date and time.
public
LocalDate
Date
Gets the local date represented by this offset date and time.
Remarks The returned <see cref="T:NodaTime.LocalDate" />
will have the same calendar system and return the same values for each of the date-based calendar
properties (Year, MonthOfYear and so on), but will not have any offset information.
public
LocalTime
TimeOfDay
Gets the time portion of this offset date and time.
Remarks The returned <see cref="T:NodaTime.LocalTime" /> will
return the same values for each of the time-based properties (Hour, Minute and so on), but
will not have any offset information.
public
Offset
Offset
Gets the offset from UTC.
Methods
public
Instant
ToInstant​()
Converts this offset date and time to an instant in time by subtracting the offset from the local date and time.
Returns The instant represented by this offset date and time
public
ZonedDateTime
InFixedZone​()
Returns this value as a <see cref="T:NodaTime.ZonedDateTime" /> .
Returns A zoned date/time with the same local time and a fixed time zone using the offset from this value.
Remarks
<para>
This method returns a <see cref="T:NodaTime.ZonedDateTime" /> with the same local date and time as this value, using a
fixed time zone with the same offset as the offset for this value.
</para> <para>
Note that because the resulting <c>ZonedDateTime</c> has a fixed time zone, it is generally not useful to
use this result for arithmetic operations, as the zone will not adjust to account for daylight savings.
</para>
public
ZonedDateTime
InZone​(DateTimeZone zone)
Returns this value in ths specified time zone. This method does not expect
the offset in the zone to be the same as for the current value; it simply converts
this value into an <see cref="T:NodaTime.Instant" /> and finds the <see cref="T:NodaTime.ZonedDateTime" />
for that instant in the specified zone.
Returns The instant represented by this value, in the specified time zone.
zone
The time zone of the new value.
ToDateTimeOffset​()
Returns the BCL <see cref="T:System.DateTimeOffset" /> corresponding to this offset date and time.
Returns A DateTimeOffset with the same local date/time and offset as this. The <see cref="T:System.DateTime" /> part of
the result always has a "kind" of Unspecified.
Remarks
<para>
If the date and time is not on a tick boundary (the unit of granularity of DateTime) the value will be truncated
towards the start of time.
</para> <para>
If the offset has a non-zero second component, this is truncated as <c>DateTimeOffset</c> has an offset
granularity of minutes.
</para> <para>
<see cref="T:System.DateTimeOffset" /> uses the Gregorian calendar by definition, so the value is implicitly converted
to the Gregorian calendar first. The result will be the same instant in time (potentially truncated as described
above), but the values returned by the Year/Month/Day properties of the <see cref="T:System.DateTimeOffset" /> may not
match the Year/Month/Day properties of this value.
</para>
public static
OffsetDateTime
FromDateTimeOffset​(System.​DateTimeOffset dateTimeOffset)
Builds an <see cref="T:NodaTime.OffsetDateTime" /> from a BCL <see cref="T:System.DateTimeOffset" /> by converting
the <see cref="T:System.DateTime" /> part to a <see cref="P:NodaTime.OffsetDateTime.LocalDateTime" /> , and the offset part to an <see cref="P:NodaTime.OffsetDateTime.Offset" /> .
Returns The converted offset date and time
dateTimeOffset
DateTimeOffset to convert
public
OffsetDateTime
WithCalendar​(CalendarSystem calendar)
Creates a new OffsetDateTime representing the same physical date, time and offset, but in a different calendar.
The returned OffsetDateTime is likely to have different date field values to this one.
For example, January 1st 1970 in the Gregorian calendar was December 19th 1969 in the Julian calendar.
Returns The converted OffsetDateTime.
calendar
The calendar system to convert this offset date and time to.
public
OffsetDateTime
With​(System.​Func<​LocalDate, LocalDate> adjuster)
Returns this offset date/time, with the given date adjuster applied to it, maintaining the existing time of day and offset.
Returns The adjusted offset date/time.
adjuster
The adjuster to apply.
Remarks
If the adjuster attempts to construct an
invalid date (such as by trying to set a day-of-month of 30 in February), any exception thrown by
that construction attempt will be propagated through this method.
public
OffsetDateTime
With​(System.​Func<​LocalTime, LocalTime> adjuster)
Returns this date/time, with the given time adjuster applied to it, maintaining the existing date and offset.
Returns The adjusted offset date/time.
adjuster
The adjuster to apply.
Remarks
If the adjuster attempts to construct an invalid time, any exception thrown by
that construction attempt will be propagated through this method.
public
OffsetDateTime
WithOffset​(Offset offset)
Creates a new OffsetDateTime representing the instant in time in the same calendar,
but with a different offset. The local date and time is adjusted accordingly.
Returns The converted OffsetDateTime.
offset
The new offset to use.
public
OffsetDate
ToOffsetDate​()
Constructs a new <see cref="T:NodaTime.OffsetDate" /> from the date and offset of this value,
but omitting the time-of-day.
Returns A value representing the date and offset aspects of this value.
public
OffsetTime
ToOffsetTime​()
Constructs a new <see cref="T:NodaTime.OffsetTime" /> from the time and offset of this value,
but omitting the date.
Returns A value representing the time and offset aspects of this value.
public
int
GetHashCode​()
Returns a hash code for this offset date and time.
See the type documentation for a description of equality semantics.
Returns A hash code for this offset date and time.
public
bool
Equals​(object obj)
Compares two <see cref="T:NodaTime.OffsetDateTime" /> values for equality.
See the type documentation for a description of equality semantics.
Returns True if the given value is another offset date/time equal to this one; false otherwise.
obj
The object to compare this date with.
public
bool
Equals​(OffsetDateTime other)
Compares two <see cref="T:NodaTime.OffsetDateTime" /> values for equality.
See the type documentation for a description of equality semantics.
Returns True if the given value is another offset date/time equal to this one; false otherwise.
other
The value to compare this offset date/time with.
public
string
ToString​()
Returns a <see cref="T:System.String" /> that represents this instance.
Returns The value of the current instance in the default format pattern ("G"), using the current thread's
culture to obtain a format provider.
public
string
ToString​(string patternText,
System.​IFormatProvider formatProvider)
Formats the value of the current instance using the specified pattern.
Returns A <see cref="T:System.String" /> containing the value of the current instance in the specified format.
patternText
The <see cref="T:System.String" /> specifying the pattern to use,
or null to use the default format pattern ("G").
formatProvider
The <see cref="T:System.IFormatProvider" /> to use when formatting the value,
or null to use the current thread's culture to obtain a format provider.
public static
OffsetDateTime
Add​(OffsetDateTime offsetDateTime,
Duration duration)
Adds a duration to an offset date and time.
Returns A new value with the time advanced by the given duration, in the same calendar system and with the same offset.
offsetDateTime
The value to add the duration to.
duration
The duration to add
Remarks
This is an alternative way of calling <see cref="M:NodaTime.OffsetDateTime.op_Addition(NodaTime.OffsetDateTime,NodaTime.Duration)" /> .
public
OffsetDateTime
Plus​(Duration duration)
Returns the result of adding a duration to this offset date and time.
Returns A new <see cref="T:NodaTime.OffsetDateTime" /> representing the result of the addition.
duration
The duration to add
Remarks
This is an alternative way of calling <see cref="M:NodaTime.OffsetDateTime.op_Addition(NodaTime.OffsetDateTime,NodaTime.Duration)" /> .
public
OffsetDateTime
PlusHours​(int hours)
Returns the result of adding a increment of hours to this offset date and time
Returns A new <see cref="T:NodaTime.OffsetDateTime" /> representing the result of the addition.
hours
The number of hours to add
public
OffsetDateTime
PlusMinutes​(int minutes)
Returns the result of adding an increment of minutes to this offset date and time
Returns A new <see cref="T:NodaTime.OffsetDateTime" /> representing the result of the addition.
minutes
The number of minutes to add
public
OffsetDateTime
PlusSeconds​(long seconds)
Returns the result of adding an increment of seconds to this offset date and time
Returns A new <see cref="T:NodaTime.OffsetDateTime" /> representing the result of the addition.
seconds
The number of seconds to add
public
OffsetDateTime
PlusMilliseconds​(long milliseconds)
Returns the result of adding an increment of milliseconds to this offset date and time
Returns A new <see cref="T:NodaTime.OffsetDateTime" /> representing the result of the addition.
milliseconds
The number of milliseconds to add
public
OffsetDateTime
PlusTicks​(long ticks)
Returns the result of adding an increment of ticks to this offset date and time
Returns A new <see cref="T:NodaTime.OffsetDateTime" /> representing the result of the addition.
ticks
The number of ticks to add
public
OffsetDateTime
PlusNanoseconds​(long nanoseconds)
Returns the result of adding an increment of nanoseconds to this offset date and time
Returns A new <see cref="T:NodaTime.OffsetDateTime" /> representing the result of the addition.
nanoseconds
The number of nanoseconds to add
public static
OffsetDateTime
Subtract​(OffsetDateTime offsetDateTime,
Duration duration)
Subtracts a duration from an offset date and time.
Returns A new value with the time "rewound" by the given duration, in the same calendar system and with the same offset.
offsetDateTime
The value to subtract the duration from.
duration
The duration to subtract.
Remarks
This is an alternative way of calling <see cref="M:NodaTime.OffsetDateTime.op_Subtraction(NodaTime.OffsetDateTime,NodaTime.Duration)" /> .
public
OffsetDateTime
Minus​(Duration duration)
Returns the result of subtracting a duration from this offset date and time, for a fluent alternative to
<see cref="M:NodaTime.OffsetDateTime.op_Subtraction(NodaTime.OffsetDateTime,NodaTime.Duration)" />
Returns A new <see cref="T:NodaTime.OffsetDateTime" /> representing the result of the subtraction.
duration
The duration to subtract
public static
Duration
Subtract​(OffsetDateTime end,
OffsetDateTime start)
Subtracts one offset date and time from another, returning an elapsed duration.
Returns The elapsed duration from <paramref name="start" /> to <paramref name="end" /> .
end
The offset date and time value to subtract from; if this is later than <paramref name="start" />
then the result will be positive.
start
The offset date and time to subtract from <paramref name="end" /> .
Remarks
This is an alternative way of calling <see cref="M:NodaTime.OffsetDateTime.op_Subtraction(NodaTime.OffsetDateTime,NodaTime.OffsetDateTime)" /> .
public
Duration
Minus​(OffsetDateTime other)
Returns the result of subtracting another offset date and time from this one, resulting in the elapsed duration
between the two instants represented in the values.
Returns The elapsed duration from <paramref name="other" /> to this value.
other
The offset date and time to subtract from this one.
Remarks
This is an alternative way of calling <see cref="M:NodaTime.OffsetDateTime.op_Subtraction(NodaTime.OffsetDateTime,NodaTime.OffsetDateTime)" /> .
AddSchema​(System.​Xml.​Schema.​XmlSchemaSet xmlSchemaSet)
Adds the XML schema type describing the structure of the <see cref="T:NodaTime.OffsetDateTime" /> XML serialization to the given <paramref name="xmlSchemaSet" /> .
Returns The qualified name of the schema type that was added to the <paramref name="xmlSchemaSet" /> .
xmlSchemaSet
The XML schema set provided by <see cref="T:System.Xml.Serialization.XmlSchemaExporter" /> .
protected
void
Finalize​()
Inherited from object
protected
object
MemberwiseClone​()
Inherited from object