Noda Time
Show / Hide Table of Contents

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, net8.0, netstandard2.0
Implements
IEquatable<OffsetTime>
IXmlSerializable
IFormattable
IEqualityOperators<OffsetTime, OffsetTime, bool>
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, IEqualityOperators<OffsetTime, OffsetTime, bool>

Constructors

OffsetTime(LocalTime, Offset)

Constructs an instance of the specified time and offset.
Since 2.3.x
Availability net6.0, net8.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, net8.0, netstandard2.0
Declaration
public int ClockHourOfHalfDay { get; }
Property Value
Type Description
int 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, net8.0, netstandard2.0
Declaration
public int Hour { get; }
Property Value
Type Description
int 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, net8.0, netstandard2.0
Declaration
public int Millisecond { get; }
Property Value
Type Description
int 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, net8.0, netstandard2.0
Declaration
public int Minute { get; }
Property Value
Type Description
int 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, net8.0, netstandard2.0
Declaration
public long NanosecondOfDay { get; }
Property Value
Type Description
long 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, net8.0, netstandard2.0
Declaration
public int NanosecondOfSecond { get; }
Property Value
Type Description
int 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, net8.0, netstandard2.0
Declaration
public 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, net8.0, netstandard2.0
Declaration
public int Second { get; }
Property Value
Type Description
int 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, net8.0, netstandard2.0
Declaration
public long TickOfDay { get; }
Property Value
Type Description
long 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, net8.0, netstandard2.0
Declaration
public int TickOfSecond { get; }
Property Value
Type Description
int 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, net8.0, netstandard2.0
Declaration
public 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, net8.0, netstandard2.0
Declaration
public static XmlQualifiedName AddSchema(XmlSchemaSet xmlSchemaSet)
Parameters
Type Name Description
XmlSchemaSet xmlSchemaSet The XML schema set provided by 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, net8.0, netstandard2.0
Declaration
public 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, net8.0, netstandard2.0
Declaration
public bool Equals(OffsetTime other)
Parameters
Type Name Description
OffsetTime other The value to compare this offset time with.
Returns
Type Description
bool 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, net8.0, netstandard2.0
Declaration
public override bool Equals(object? obj)
Parameters
Type Name Description
object obj The object to compare this offset time with.
Returns
Type Description
bool True if the given value is another offset time equal to this one; false otherwise.
Overrides
ValueType.Equals(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, net8.0, netstandard2.0
Declaration
public override int GetHashCode()
Returns
Type Description
int A hash code for this offset time.
Overrides
ValueType.GetHashCode()

On(LocalDate)

Combines this OffsetTime with the given LocalDate into an OffsetDateTime.
Since 2.3.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public 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 string that represents this instance.
Since 2.3.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public override 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
ValueType.ToString()

ToString(string?, IFormatProvider?)

Formats the value of the current instance using the specified pattern.
Since 2.3.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public string ToString(string? patternText, IFormatProvider? formatProvider)
Parameters
Type Name Description
string patternText The string specifying the pattern to use, or null to use the default format pattern ("G").
IFormatProvider formatProvider The 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 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, net8.0, netstandard2.0
Declaration
public 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, net8.0, netstandard2.0
Declaration
public 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

operator ==(OffsetTime, OffsetTime)

Implements the operator == (equality). See the type documentation for a description of equality semantics.
Since 2.3.x
Availability net6.0, net8.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
bool true if values are equal to each other, otherwise false.

operator !=(OffsetTime, OffsetTime)

Implements the operator != (inequality). See the type documentation for a description of equality semantics.
Since 2.3.x
Availability net6.0, net8.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
bool true if values are not equal to each other, otherwise false.

Explicit Interface Implementations

IXmlSerializable.GetSchema()

This method is reserved and should not be used. When implementing the IXmlSerializable interface, you should return null (Nothing in Visual Basic) from this method, and instead, if specifying a custom schema is required, apply the XmlSchemaProviderAttribute to the class.
Since 3.2.x
Availability net6.0, net8.0, netstandard2.0
Declaration
XmlSchema IXmlSerializable.GetSchema()
Returns
Type Description
XmlSchema An XmlSchema that describes the XML representation of the object that is produced by the WriteXml(XmlWriter) method and consumed by the ReadXml(XmlReader) method.

IXmlSerializable.ReadXml(XmlReader)

Generates an object from its XML representation.
Since 2.3.x
Availability net6.0, net8.0, netstandard2.0
Declaration
void IXmlSerializable.ReadXml(XmlReader reader)
Parameters
Type Name Description
XmlReader reader The XmlReader stream from which the object is deserialized.

IXmlSerializable.WriteXml(XmlWriter)

Converts an object into its XML representation.
Since 2.3.x
Availability net6.0, net8.0, netstandard2.0
Declaration
void IXmlSerializable.WriteXml(XmlWriter writer)
Parameters
Type Name Description
XmlWriter writer The XmlWriter stream to which the object is serialized.

Implements

IEquatable<T>
IXmlSerializable
IFormattable
IEqualityOperators<TSelf, TOther, TResult>
In this article
Back to top Generated by DocFX