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 netstandard2.0
Implements
IEquatable<OffsetTime>
IXmlSerializable
IFormattable
Inherited Members
Object.Equals(Object, Object)
Object.GetType()
Object.ReferenceEquals(Object, Object)
Namespace: NodaTime
Assembly: NodaTime.dll
Syntax
[TypeConverter(typeof(OffsetTimeTypeConverter))]
public struct OffsetTime : IEquatable<OffsetTime>, IXmlSerializable, IFormattable

Constructors

OffsetTime(LocalTime, Offset)

Constructs an instance of the specified time and offset.
Since 2.3.x
Availability 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 netstandard2.0
Declaration
public 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 netstandard2.0
Declaration
public 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 netstandard2.0
Declaration
public 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 netstandard2.0
Declaration
public 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 netstandard2.0
Declaration
public 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 netstandard2.0
Declaration
public 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 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 netstandard2.0
Declaration
public 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 netstandard2.0
Declaration
public 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 netstandard2.0
Declaration
public 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 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 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 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 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
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 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
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 netstandard2.0
Declaration
public override int GetHashCode()
Returns
Type Description
Int32 A hash code for this offset time.
Overrides
System.ValueType.GetHashCode()

On(LocalDate)

Combines this OffsetTime with the given LocalDate into an OffsetDateTime.
Since 2.3.x
Availability 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 System.String that represents this instance.
Since 2.3.x
Availability 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
System.ValueType.ToString()

ToString(String, IFormatProvider)

Formats the value of the current instance using the specified pattern.
Since 2.3.x
Availability netstandard2.0
Declaration
public 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 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 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

Equality(OffsetTime, OffsetTime)

Implements the operator == (equality). See the type documentation for a description of equality semantics.
Since 2.3.x
Availability 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 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.GetSchema()

Since 2.3.x
Availability netstandard2.0
Declaration
XmlSchema IXmlSerializable.GetSchema()
Returns
Type Description
XmlSchema

IXmlSerializable.ReadXml(XmlReader)

Since 2.3.x
Availability netstandard2.0
Declaration
void IXmlSerializable.ReadXml(XmlReader reader)
Parameters
Type Name Description
XmlReader reader

IXmlSerializable.WriteXml(XmlWriter)

Since 2.3.x
Availability netstandard2.0
Declaration
void IXmlSerializable.WriteXml(XmlWriter writer)
Parameters
Type Name Description
XmlWriter writer

Implements

System.IEquatable<T>
System.Xml.Serialization.IXmlSerializable
System.IFormattable
In this article
Back to top Generated by DocFX