Struct OffsetTime
A combination of a LocalTime and an Offset, to represent
a time-of-day at a specific offset from UTC but without any date information.
Since 2.3.x
Availability net6.0, netstandard2.0
Inherited Members
Object.Equals(Object, Object)
Object.GetType()
Object.ReferenceEquals(Object, Object)
Namespace: NodaTime
Assembly: NodaTime.dll
Syntax
[TypeConverter(typeof(OffsetTimeTypeConverter))]
public readonly struct OffsetTime : IEquatable<OffsetTime>, IXmlSerializable, IFormattable
Constructors
OffsetTime(LocalTime, Offset)
Constructs an instance of the specified time and offset.
Since 2.3.x
Availability net6.0, netstandard2.0
Declaration
public OffsetTime(LocalTime time, Offset offset)
Parameters
Type | Name | Description |
---|---|---|
LocalTime | time | The time part of the value. |
Offset | offset | The offset part of the value. |
Sample snippet
using NodaTime;
using System;
OffsetTime offsetTime = new OffsetTime(
new LocalTime(15, 20, 48),
Offset.FromHours(3));
Console.WriteLine(offsetTime.TimeOfDay);
Console.WriteLine(offsetTime.Offset);
Output:
15:20:48
+03
Properties
ClockHourOfHalfDay
Gets the hour of the half-day of this offset time, in the range 1 to 12 inclusive.
Since 2.3.x
Availability net6.0, netstandard2.0
Declaration
public readonly int ClockHourOfHalfDay { get; }
Property Value
Type | Description |
---|---|
Int32 | The hour of the half-day of this offset time, in the range 1 to 12 inclusive. |
Hour
Gets the hour of day of this offset time, in the range 0 to 23 inclusive.
Since 2.3.x
Availability net6.0, netstandard2.0
Declaration
public readonly int Hour { get; }
Property Value
Type | Description |
---|---|
Int32 | The hour of day of this offset time, in the range 0 to 23 inclusive. |
Millisecond
Gets the millisecond of this offset time within the second, in the range 0 to 999 inclusive.
Since 2.3.x
Availability net6.0, netstandard2.0
Declaration
public readonly int Millisecond { get; }
Property Value
Type | Description |
---|---|
Int32 | The millisecond of this offset time within the second, in the range 0 to 999 inclusive. |
Minute
Gets the minute of this offset time, in the range 0 to 59 inclusive.
Since 2.3.x
Availability net6.0, netstandard2.0
Declaration
public readonly int Minute { get; }
Property Value
Type | Description |
---|---|
Int32 | The minute of this offset time, in the range 0 to 59 inclusive. |
NanosecondOfDay
Gets the nanosecond of this offset time within the day, in the range 0 to 86,399,999,999,999 inclusive.
Since 2.3.x
Availability net6.0, netstandard2.0
Declaration
public readonly long NanosecondOfDay { get; }
Property Value
Type | Description |
---|---|
Int64 | The nanosecond of this offset time within the day, in the range 0 to 86,399,999,999,999 inclusive. |
NanosecondOfSecond
Gets the nanosecond of this offset time within the second, in the range 0 to 999,999,999 inclusive.
Since 2.3.x
Availability net6.0, netstandard2.0
Declaration
public readonly int NanosecondOfSecond { get; }
Property Value
Type | Description |
---|---|
Int32 | The nanosecond of this offset time within the second, in the range 0 to 999,999,999 inclusive. |
Offset
Gets the offset from UTC of this value.
The offset from UTC of this value.
Since 2.3.x
Availability net6.0, netstandard2.0
Declaration
public readonly Offset Offset { get; }
Property Value
Type | Description |
---|---|
Offset |
Second
Gets the second of this offset time within the minute, in the range 0 to 59 inclusive.
Since 2.3.x
Availability net6.0, netstandard2.0
Declaration
public readonly int Second { get; }
Property Value
Type | Description |
---|---|
Int32 | The second of this offset time within the minute, in the range 0 to 59 inclusive. |
TickOfDay
Gets the tick of this offset time within the day, in the range 0 to 863,999,999,999 inclusive.
Since 2.3.x
Availability net6.0, netstandard2.0
Declaration
public readonly long TickOfDay { get; }
Property Value
Type | Description |
---|---|
Int64 | The tick of this offset time within the day, in the range 0 to 863,999,999,999 inclusive. |
Remarks
If the value does not fall on a tick boundary, it will be truncated towards zero.
TickOfSecond
Gets the tick of this offset time within the second, in the range 0 to 9,999,999 inclusive.
Since 2.3.x
Availability net6.0, netstandard2.0
Declaration
public readonly int TickOfSecond { get; }
Property Value
Type | Description |
---|---|
Int32 | The tick of this offset time within the second, in the range 0 to 9,999,999 inclusive. |
TimeOfDay
Gets the time-of-day represented by this value.
Since 2.3.x
Availability net6.0, netstandard2.0
Declaration
public readonly LocalTime TimeOfDay { get; }
Property Value
Type | Description |
---|---|
LocalTime | The time-of-day represented by this value. |
Methods
AddSchema(XmlSchemaSet)
Adds the XML schema type describing the structure of the OffsetTime XML serialization to the given
xmlSchemaSet
.
Since 3.0.x
Availability net6.0, netstandard2.0
Declaration
public static XmlQualifiedName AddSchema(XmlSchemaSet xmlSchemaSet)
Parameters
Type | Name | Description |
---|---|---|
XmlSchemaSet | xmlSchemaSet | The XML schema set provided by System.Xml.Serialization.XmlSchemaExporter. |
Returns
Type | Description |
---|---|
XmlQualifiedName | The qualified name of the schema type that was added to the xmlSchemaSet . |
Deconstruct(out LocalTime, out Offset)
Deconstruct this value into its components.
Since 2.3.x
Availability net6.0, netstandard2.0
Declaration
public readonly void Deconstruct(out LocalTime localTime, out Offset offset)
Parameters
Type | Name | Description |
---|---|---|
LocalTime | localTime | The LocalTime component. |
Offset | offset | The Offset component. |
Equals(OffsetTime)
Compares two OffsetTime values for equality.
See the type documentation for a description of equality semantics.
Since 2.3.x
Availability net6.0, netstandard2.0
Declaration
public readonly bool Equals(OffsetTime other)
Parameters
Type | Name | Description |
---|---|---|
OffsetTime | other | The value to compare this offset time with. |
Returns
Type | Description |
---|---|
Boolean | True if the given value is another offset time equal to this one; false otherwise. |
Equals(Object)
Compares two OffsetTime values for equality.
See the type documentation for a description of equality semantics.
Since 2.3.x
Availability net6.0, netstandard2.0
Declaration
public override readonly bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
Object | obj | The object to compare this offset time with. |
Returns
Type | Description |
---|---|
Boolean | True if the given value is another offset time equal to this one; false otherwise. |
Overrides
System.ValueType.Equals(System.Object)
GetHashCode()
Returns a hash code for this offset time.
See the type documentation for a description of equality semantics.
Since 2.3.x
Availability net6.0, netstandard2.0
Declaration
public override readonly int GetHashCode()
Returns
Type | Description |
---|---|
Int32 | A hash code for this offset time. |
Overrides
System.ValueType.GetHashCode()
On(LocalDate)
Since 2.3.x
Availability net6.0, netstandard2.0
Declaration
public readonly OffsetDateTime On(LocalDate date)
Parameters
Type | Name | Description |
---|---|---|
LocalDate | date | The date to combine with this time-of-day. |
Returns
Type | Description |
---|---|
OffsetDateTime | The OffsetDateTime representation of this time-of-day on the given date. |
ToString()
Returns a System.String that represents this instance.
Since 2.3.x
Availability net6.0, netstandard2.0
Declaration
public override readonly string ToString()
Returns
Type | Description |
---|---|
String | The value of the current instance in the default format pattern ("G"), using the current thread's culture to obtain a format provider. |
Overrides
System.ValueType.ToString()
ToString(String, IFormatProvider)
Formats the value of the current instance using the specified pattern.
Since 2.3.x
Availability net6.0, netstandard2.0
Declaration
public readonly string ToString(string patternText, IFormatProvider formatProvider)
Parameters
Type | Name | Description |
---|---|---|
String | patternText | The System.String specifying the pattern to use, or null to use the default format pattern ("G"). |
IFormatProvider | formatProvider | The System.IFormatProvider to use when formatting the value, or null to use the current thread's culture to obtain a format provider. |
Returns
Type | Description |
---|---|
String | A System.String containing the value of the current instance in the specified format. |
With(Func<LocalTime, LocalTime>)
Returns this offset time-of-day, with the given date adjuster applied to it, maintaining the existing offset.
Since 2.3.x
Availability net6.0, netstandard2.0
Declaration
public readonly OffsetTime With(Func<LocalTime, LocalTime> adjuster)
Parameters
Type | Name | Description |
---|---|---|
Func<LocalTime, LocalTime> | adjuster | The adjuster to apply. |
Returns
Type | Description |
---|---|
OffsetTime | The adjusted offset date. |
Remarks
If the adjuster attempts to construct an invalid time-of-day, any exception thrown by
that construction attempt will be propagated through this method.
Sample snippet
using NodaTime;
using System;
OffsetTime original = new OffsetTime(
new LocalTime(15, 20, 48),
Offset.FromHours(3));
OffsetTime updated = original.With(x => x.PlusHours(5));
Console.WriteLine(updated.TimeOfDay);
Console.WriteLine(updated.Offset);
Output:
20:20:48
+03
WithOffset(Offset)
Creates a new OffsetTime for the same time-of-day, but with the specified UTC offset.
Since 2.3.x
Availability net6.0, netstandard2.0
Declaration
public readonly OffsetTime WithOffset(Offset offset)
Parameters
Type | Name | Description |
---|---|---|
Offset | offset | The new UTC offset. |
Returns
Type | Description |
---|---|
OffsetTime | A new OffsetTime for the same date, but with the specified UTC offset. |
Sample snippet
using NodaTime;
using System;
OffsetTime original = new OffsetTime(
new LocalTime(15, 20, 48),
Offset.FromHours(3));
OffsetTime updated = original.WithOffset(Offset.FromHours(-3));
Console.WriteLine(updated.TimeOfDay);
Console.WriteLine(updated.Offset);
Output:
15:20:48
-03
Operators
Equality(OffsetTime, OffsetTime)
Implements the operator == (equality).
See the type documentation for a description of equality semantics.
Since 2.3.x
Availability net6.0, netstandard2.0
Declaration
public static bool operator ==(OffsetTime left, OffsetTime right)
Parameters
Type | Name | Description |
---|---|---|
OffsetTime | left | The left hand side of the operator. |
OffsetTime | right | The right hand side of the operator. |
Returns
Type | Description |
---|---|
Boolean | true if values are equal to each other, otherwise false . |
Inequality(OffsetTime, OffsetTime)
Implements the operator != (inequality).
See the type documentation for a description of equality semantics.
Since 2.3.x
Availability net6.0, netstandard2.0
Declaration
public static bool operator !=(OffsetTime left, OffsetTime right)
Parameters
Type | Name | Description |
---|---|---|
OffsetTime | left | The left hand side of the operator. |
OffsetTime | right | The right hand side of the operator. |
Returns
Type | Description |
---|---|
Boolean | true if values are not equal to each other, otherwise false . |
Explicit Interface Implementations
IXmlSerializable.ReadXml(XmlReader)
Since 2.3.x
Availability net6.0, netstandard2.0
Declaration
readonly void IXmlSerializable.ReadXml(XmlReader reader)
Parameters
Type | Name | Description |
---|---|---|
XmlReader | reader |
IXmlSerializable.WriteXml(XmlWriter)
Since 2.3.x
Availability net6.0, netstandard2.0
Declaration
readonly void IXmlSerializable.WriteXml(XmlWriter writer)
Parameters
Type | Name | Description |
---|---|---|
XmlWriter | writer |
Implements
System.IEquatable<T>
System.Xml.Serialization.IXmlSerializable
System.IFormattable