Struct LocalTime
LocalTime is an immutable struct representing a time of day, with no reference
to a particular calendar, time zone or date.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Implements
Inherited Members
Namespace: NodaTime
Assembly: NodaTime.dll
Syntax
[TypeConverter(typeof(LocalTimeTypeConverter))]
public readonly struct LocalTime : IEquatable<LocalTime>, IComparable<LocalTime>, IFormattable, IComparable, IXmlSerializable, IAdditionOperators<LocalTime, Period, LocalTime>, ISubtractionOperators<LocalTime, LocalTime, Period>, ISubtractionOperators<LocalTime, Period, LocalTime>, IComparisonOperators<LocalTime, LocalTime, bool>, IEqualityOperators<LocalTime, LocalTime, bool>, IMinMaxValue<LocalTime>
Remarks
Ordering and equality are defined in the natural way, simply comparing the number of "nanoseconds since midnight".
The default value of this type is Midnight.
Constructors
LocalTime(int, int)
Creates a local time at the given hour and minute, with second, millisecond-of-second
and tick-of-millisecond values of zero.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public LocalTime(int hour, int minute)
Parameters
| Type | Name | Description |
|---|---|---|
| int | hour | The hour of day. |
| int | minute | The minute of the hour. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | The parameters do not form a valid time. |
LocalTime(int, int, int)
Creates a local time at the given hour, minute and second,
with millisecond-of-second and tick-of-millisecond values of zero.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public LocalTime(int hour, int minute, int second)
Parameters
| Type | Name | Description |
|---|---|---|
| int | hour | The hour of day. |
| int | minute | The minute of the hour. |
| int | second | The second of the minute. |
Sample snippet
using NodaTime;
using System;
using System.Globalization;
LocalTime time = new LocalTime(16, 20, 0);
Console.WriteLine(time.ToString("HH:mm:ss", CultureInfo.InvariantCulture));
Output:
16:20:00
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | The parameters do not form a valid time. |
LocalTime(int, int, int, int)
Creates a local time at the given hour, minute, second and millisecond,
with a tick-of-millisecond value of zero.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public LocalTime(int hour, int minute, int second, int millisecond)
Parameters
| Type | Name | Description |
|---|---|---|
| int | hour | The hour of day. |
| int | minute | The minute of the hour. |
| int | second | The second of the minute. |
| int | millisecond | The millisecond of the second. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | The parameters do not form a valid time. |
Properties
ClockHourOfHalfDay
Gets the hour of the half-day of this local time, in the range 1 to 12 inclusive.
Since 1.0.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 local time, in the range 1 to 12 inclusive. |
Hour
Gets the hour of day of this local time, in the range 0 to 23 inclusive.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public int Hour { get; }
Property Value
| Type | Description |
|---|---|
| int | The hour of day of this local time, in the range 0 to 23 inclusive. |
MaxValue
The maximum value of this type, one nanosecond before midnight.
Since 2.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static LocalTime MaxValue { get; }
Property Value
| Type | Description |
|---|---|
| LocalTime |
Remarks
This is useful if you have to use an inclusive upper bound for some reason.
In general, it's better to use an exclusive upper bound, in which case use midnight of
the following day.
Midnight
Local time at midnight, i.e. 0 hours, 0 minutes, 0 seconds.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static LocalTime Midnight { get; }
Property Value
| Type | Description |
|---|---|
| LocalTime |
Millisecond
Gets the millisecond of this local time within the second, in the range 0 to 999 inclusive.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public int Millisecond { get; }
Property Value
| Type | Description |
|---|---|
| int | The millisecond of this local time within the second, in the range 0 to 999 inclusive. |
MinValue
The minimum value of this type; equivalent to Midnight.
Since 2.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static LocalTime MinValue { get; }
Property Value
| Type | Description |
|---|---|
| LocalTime |
Minute
Gets the minute of this local time, in the range 0 to 59 inclusive.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public int Minute { get; }
Property Value
| Type | Description |
|---|---|
| int | The minute of this local time, in the range 0 to 59 inclusive. |
NanosecondOfDay
Gets the nanosecond of this local time within the day, in the range 0 to 86,399,999,999,999 inclusive.
Since 2.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public long NanosecondOfDay { get; }
Property Value
| Type | Description |
|---|---|
| long | The nanosecond of this local time within the day, in the range 0 to 86,399,999,999,999 inclusive. |
NanosecondOfSecond
Gets the nanosecond of this local time within the second, in the range 0 to 999,999,999 inclusive.
Since 2.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public int NanosecondOfSecond { get; }
Property Value
| Type | Description |
|---|---|
| int | The nanosecond of this local time within the second, in the range 0 to 999,999,999 inclusive. |
Noon
Local time at noon, i.e. 12 hours, 0 minutes, 0 seconds.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static LocalTime Noon { get; }
Property Value
| Type | Description |
|---|---|
| LocalTime |
Second
Gets the second of this local time within the minute, in the range 0 to 59 inclusive.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public int Second { get; }
Property Value
| Type | Description |
|---|---|
| int | The second of this local time within the minute, in the range 0 to 59 inclusive. |
TickOfDay
Gets the tick of this local time within the day, in the range 0 to 863,999,999,999 inclusive.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public long TickOfDay { get; }
Property Value
| Type | Description |
|---|---|
| long | The tick of this local 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 local time within the second, in the range 0 to 9,999,999 inclusive.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public int TickOfSecond { get; }
Property Value
| Type | Description |
|---|---|
| int | The tick of this local time within the second, in the range 0 to 9,999,999 inclusive. |
Methods
Add(LocalTime, Period)
Adds the specified period to the time. Friendly alternative to
operator+().
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static LocalTime Add(LocalTime time, Period period)
Parameters
| Type | Name | Description |
|---|---|---|
| LocalTime | time | The time to add the period to |
| Period | period | The period to add. Must not contain any (non-zero) date units. |
Returns
| Type | Description |
|---|---|
| LocalTime | The sum of the given time and period |
AddSchema(XmlSchemaSet)
Adds the XML schema type describing the structure of the LocalTime XML serialization to the given
xmlSchemaSet.
the 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. |
CompareTo(LocalTime)
Indicates whether this time is earlier, later or the same as another one.
See the type documentation for a description of ordering semantics.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public int CompareTo(LocalTime other)
Parameters
| Type | Name | Description |
|---|---|---|
| LocalTime | other | The other date/time to compare this one with |
Returns
| Type | Description |
|---|---|
| int | A value less than zero if this time is earlier than other;
zero if this time is the same as other; a value greater than zero if this time is
later than other. |
Deconstruct(out int, out int, out int)
Deconstruct this time into its components.
Since 2.3.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public void Deconstruct(out int hour, out int minute, out int second)
Parameters
| Type | Name | Description |
|---|---|---|
| int | hour | The hour of the time. |
| int | minute | The minute of the hour. |
| int | second | The second within the minute. |
Equals(LocalTime)
Compares this local time with the specified one for equality.
See the type documentation for a description of equality semantics.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public bool Equals(LocalTime other)
Parameters
| Type | Name | Description |
|---|---|---|
| LocalTime | other | The other local time to compare this one with |
Returns
| Type | Description |
|---|---|
| bool | True if the specified time is equal to this one; false otherwise |
Equals(object?)
Compares this local time with the specified reference.
See the type documentation for a description of equality semantics.
Since 1.0.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 one with |
Returns
| Type | Description |
|---|---|
| bool | True if the specified value is a local time which is equal to this one; false otherwise |
Overrides
FromHourMinuteSecondMillisecondTick(int, int, int, int, int)
Factory method to create a local time at the given hour, minute, second, millisecond and tick within millisecond.
Since 1.4.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static LocalTime FromHourMinuteSecondMillisecondTick(int hour, int minute, int second, int millisecond, int tickWithinMillisecond)
Parameters
| Type | Name | Description |
|---|---|---|
| int | hour | The hour of day. |
| int | minute | The minute of the hour. |
| int | second | The second of the minute. |
| int | millisecond | The millisecond of the second. |
| int | tickWithinMillisecond | The tick within the millisecond. |
Returns
| Type | Description |
|---|---|
| LocalTime | The resulting time. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | The parameters do not form a valid time. |
FromHourMinuteSecondNanosecond(int, int, int, long)
Factory method for creating a local time from the hour of day, minute of hour, second of minute, and nanosecond of second.
Since 2.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static LocalTime FromHourMinuteSecondNanosecond(int hour, int minute, int second, long nanosecondWithinSecond)
Parameters
| Type | Name | Description |
|---|---|---|
| int | hour | The hour of day in the desired time, in the range [0, 23]. |
| int | minute | The minute of hour in the desired time, in the range [0, 59]. |
| int | second | The second of minute in the desired time, in the range [0, 59]. |
| long | nanosecondWithinSecond | The nanosecond within the second in the desired time, in the range [0, 999999999]. |
Returns
| Type | Description |
|---|---|
| LocalTime | The resulting time. |
Remarks
This is not a constructor overload as it would have the same signature as the one taking millisecond of second.
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | The parameters do not form a valid time. |
FromHourMinuteSecondTick(int, int, int, int)
Factory method for creating a local time from the hour of day, minute of hour, second of minute, and tick of second.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static LocalTime FromHourMinuteSecondTick(int hour, int minute, int second, int tickWithinSecond)
Parameters
| Type | Name | Description |
|---|---|---|
| int | hour | The hour of day in the desired time, in the range [0, 23]. |
| int | minute | The minute of hour in the desired time, in the range [0, 59]. |
| int | second | The second of minute in the desired time, in the range [0, 59]. |
| int | tickWithinSecond | The tick within the second in the desired time, in the range [0, 9999999]. |
Returns
| Type | Description |
|---|---|
| LocalTime | The resulting time. |
Remarks
This is not a constructor overload as it would have the same signature as the one taking millisecond of second.
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | The parameters do not form a valid time. |
FromHoursSinceMidnight(int)
Factory method for creating a local time from the number of hours which have elapsed since midnight.
Since 3.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static LocalTime FromHoursSinceMidnight(int hours)
Parameters
| Type | Name | Description |
|---|---|---|
| int | hours | The number of hours, in the range [0, 23] |
Returns
| Type | Description |
|---|---|
| LocalTime | The resulting time. |
FromMillisecondsSinceMidnight(int)
Factory method for creating a local time from the number of milliseconds which have elapsed since midnight.
Since 1.1.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static LocalTime FromMillisecondsSinceMidnight(int milliseconds)
Parameters
| Type | Name | Description |
|---|---|---|
| int | milliseconds | The number of milliseconds, in the range [0, 86,399,999] |
Returns
| Type | Description |
|---|---|
| LocalTime | The resulting time. |
FromMinutesSinceMidnight(int)
Factory method for creating a local time from the number of minutes which have elapsed since midnight.
Since 3.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static LocalTime FromMinutesSinceMidnight(int minutes)
Parameters
| Type | Name | Description |
|---|---|---|
| int | minutes | The number of minutes, in the range [0, 1439] |
Returns
| Type | Description |
|---|---|
| LocalTime | The resulting time. |
FromNanosecondsSinceMidnight(long)
Factory method for creating a local time from the number of nanoseconds which have elapsed since midnight.
Since 3.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static LocalTime FromNanosecondsSinceMidnight(long nanoseconds)
Parameters
| Type | Name | Description |
|---|---|---|
| long | nanoseconds | The number of nanoseconds, in the range [0, 86,399,999,999,999] |
Returns
| Type | Description |
|---|---|
| LocalTime | The resulting time. |
FromSecondsSinceMidnight(int)
Factory method for creating a local time from the number of seconds which have elapsed since midnight.
Since 1.1.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static LocalTime FromSecondsSinceMidnight(int seconds)
Parameters
| Type | Name | Description |
|---|---|---|
| int | seconds | The number of seconds, in the range [0, 86,399] |
Returns
| Type | Description |
|---|---|
| LocalTime | The resulting time. |
FromTicksSinceMidnight(long)
Factory method for creating a local time from the number of ticks which have elapsed since midnight.
Since 1.1.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static LocalTime FromTicksSinceMidnight(long ticks)
Parameters
| Type | Name | Description |
|---|---|---|
| long | ticks | The number of ticks, in the range [0, 863,999,999,999] |
Returns
| Type | Description |
|---|---|
| LocalTime | The resulting time. |
FromTimeOnly(TimeOnly)
Since 3.1.x
Availability net6.0, net8.0
Declaration
public static LocalTime FromTimeOnly(TimeOnly time)
Parameters
| Type | Name | Description |
|---|---|---|
| TimeOnly | time | The time of day to convert. |
Returns
| Type | Description |
|---|---|
| LocalTime | The LocalTime equivalent. |
GetHashCode()
Returns a hash code for this local time.
See the type documentation for a description of equality semantics.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| int | A hash code for this local time. |
Overrides
Max(LocalTime, LocalTime)
Returns the later time of the given two.
Since 2.3.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static LocalTime Max(LocalTime x, LocalTime y)
Parameters
| Type | Name | Description |
|---|---|---|
| LocalTime | x | The first time to compare. |
| LocalTime | y | The second time to compare. |
Returns
| Type | Description |
|---|---|
| LocalTime | The later instant of x or y. |
Min(LocalTime, LocalTime)
Returns the earlier time of the given two.
Since 2.3.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static LocalTime Min(LocalTime x, LocalTime y)
Parameters
| Type | Name | Description |
|---|---|---|
| LocalTime | x | The first time to compare. |
| LocalTime | y | The second time to compare. |
Returns
| Type | Description |
|---|---|
| LocalTime | The earlier time of x or y. |
Minus(LocalTime)
Subtracts the specified time from this time, returning the result as a Period.
Fluent alternative to
operator-().
Since 2.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public Period Minus(LocalTime time)
Parameters
| Type | Name | Description |
|---|---|---|
| LocalTime | time | The time to subtract from this |
Returns
| Type | Description |
|---|---|
| Period | The difference between the specified time and this one |
Minus(Period)
Subtracts the specified period from this time. Fluent alternative to
operator-().
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public LocalTime Minus(Period period)
Parameters
| Type | Name | Description |
|---|---|---|
| Period | period | The period to subtract. Must not contain any (non-zero) date units. |
Returns
| Type | Description |
|---|---|
| LocalTime | The result of subtracting the given period from this time. |
On(LocalDate)
Combines this LocalTime with the given LocalDate
into a single LocalDateTime.
Fluent alternative to
operator+().
Since 1.3.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public LocalDateTime On(LocalDate date)
Parameters
| Type | Name | Description |
|---|---|---|
| LocalDate | date | The date to combine with this time |
Returns
| Type | Description |
|---|---|
| LocalDateTime | The LocalDateTime representation of the given time on this date |
Plus(Period)
Adds the specified period to this time. Fluent alternative to
operator+().
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public LocalTime Plus(Period period)
Parameters
| Type | Name | Description |
|---|---|---|
| Period | period | The period to add. Must not contain any (non-zero) date units. |
Returns
| Type | Description |
|---|---|
| LocalTime | The sum of this time and the given period |
PlusHours(long)
Returns a new LocalTime representing the current value with the given number of hours added.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public LocalTime PlusHours(long hours)
Parameters
| Type | Name | Description |
|---|---|---|
| long | hours | The number of hours to add |
Returns
| Type | Description |
|---|---|
| LocalTime | The current value plus the given number of hours. |
Remarks
If the value goes past the start or end of the day, it wraps - so 11pm plus two hours is 1am, for example.
PlusMilliseconds(long)
Returns a new LocalTime representing the current value with the given number of milliseconds added.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public LocalTime PlusMilliseconds(long milliseconds)
Parameters
| Type | Name | Description |
|---|---|---|
| long | milliseconds | The number of milliseconds to add |
Returns
| Type | Description |
|---|---|
| LocalTime | The current value plus the given number of milliseconds. |
PlusMinutes(long)
Returns a new LocalTime representing the current value with the given number of minutes added.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public LocalTime PlusMinutes(long minutes)
Parameters
| Type | Name | Description |
|---|---|---|
| long | minutes | The number of minutes to add |
Returns
| Type | Description |
|---|---|
| LocalTime | The current value plus the given number of minutes. |
Remarks
If the value goes past the start or end of the day, it wraps - so 11pm plus 120 minutes is 1am, for example.
PlusNanoseconds(long)
Returns a new LocalTime representing the current value with the given number of nanoseconds added.
Since 2.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public LocalTime PlusNanoseconds(long nanoseconds)
Parameters
| Type | Name | Description |
|---|---|---|
| long | nanoseconds | The number of nanoseconds to add |
Returns
| Type | Description |
|---|---|
| LocalTime | The current value plus the given number of ticks. |
PlusSeconds(long)
Returns a new LocalTime representing the current value with the given number of seconds added.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public LocalTime PlusSeconds(long seconds)
Parameters
| Type | Name | Description |
|---|---|---|
| long | seconds | The number of seconds to add |
Returns
| Type | Description |
|---|---|
| LocalTime | The current value plus the given number of seconds. |
Remarks
If the value goes past the start or end of the day, it wraps - so 11:59pm plus 120 seconds is 12:01am, for example.
PlusTicks(long)
Returns a new LocalTime representing the current value with the given number of ticks added.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public LocalTime PlusTicks(long ticks)
Parameters
| Type | Name | Description |
|---|---|---|
| long | ticks | The number of ticks to add |
Returns
| Type | Description |
|---|---|
| LocalTime | The current value plus the given number of ticks. |
Subtract(LocalTime, LocalTime)
Subtracts one time from another, returning the result as a Period with units of years, months and days.
Since 2.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static Period Subtract(LocalTime lhs, LocalTime rhs)
Parameters
| Type | Name | Description |
|---|---|---|
| LocalTime | lhs | The time to subtract from |
| LocalTime | rhs | The time to subtract |
Returns
| Type | Description |
|---|---|
| Period | The result of subtracting one time from another. |
Remarks
This is simply a convenience method for calling Between(LocalTime, LocalTime).
Subtract(LocalTime, Period)
Subtracts the specified period from the time. Friendly alternative to
operator-().
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static LocalTime Subtract(LocalTime time, Period period)
Parameters
| Type | Name | Description |
|---|---|---|
| LocalTime | time | The time to subtract the period from |
| Period | period | The period to subtract. Must not contain any (non-zero) date units. |
Returns
| Type | Description |
|---|---|
| LocalTime | The result of subtracting the given period from the time. |
ToString()
Returns a string that represents this instance.
Since 1.0.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 ("T"), using the current thread's culture to obtain a format provider. |
Overrides
ToString(string?, IFormatProvider?)
Formats the value of the current instance using the specified pattern.
Since 1.0.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 ("T"). |
| 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. |
ToTimeOnly()
Converts this value to an equivalent TimeOnly.
Since 3.1.x
Availability net6.0, net8.0
Declaration
public TimeOnly ToTimeOnly()
Returns
| Type | Description |
|---|---|
| TimeOnly | A TimeOnly value equivalent to this one. |
Remarks
If the value does not fall on a tick boundary, it will be truncated to the earlier tick boundary.
With(Func<LocalTime, LocalTime>)
Returns this time, with the given adjuster applied to it.
Since 2.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public LocalTime With(Func<LocalTime, LocalTime> adjuster)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<LocalTime, LocalTime> | adjuster | The adjuster to apply. |
Returns
| Type | Description |
|---|---|
| LocalTime | The adjusted time. |
Remarks
If the adjuster attempts to construct an invalid time, any exception thrown by
that construction attempt will be propagated through this method.
WithOffset(Offset)
Returns an OffsetTime for this time-of-day with the given 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 offset to apply. |
Returns
| Type | Description |
|---|---|
| OffsetTime | The result of this time-of-day offset by the given amount. |
Remarks
This method is purely a convenient alternative to calling the OffsetTime constructor directly.
Operators
operator +(LocalTime, Period)
Creates a new local time by adding a period to an existing time. The period must not contain
any date-related units (days etc) with non-zero values.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static LocalTime operator +(LocalTime time, Period period)
Parameters
| Type | Name | Description |
|---|---|---|
| LocalTime | time | The time to add the period to |
| Period | period | The period to add |
Returns
| Type | Description |
|---|---|
| LocalTime | The result of adding the period to the time, wrapping via midnight if necessary |
operator ==(LocalTime, LocalTime)
Compares two local times for equality.
See the type documentation for a description of equality semantics.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static bool operator ==(LocalTime lhs, LocalTime rhs)
Parameters
| Type | Name | Description |
|---|---|---|
| LocalTime | lhs | The first value to compare |
| LocalTime | rhs | The second value to compare |
Returns
| Type | Description |
|---|---|
| bool | True if the two times are the same; false otherwise |
operator >(LocalTime, LocalTime)
Compares two LocalTime values to see if the left one is strictly later than the right one.
See the type documentation for a description of ordering semantics.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static bool operator >(LocalTime lhs, LocalTime rhs)
Parameters
| Type | Name | Description |
|---|---|---|
| LocalTime | lhs | First operand of the comparison |
| LocalTime | rhs | Second operand of the comparison |
Returns
| Type | Description |
|---|---|
| bool | true if the lhs is strictly later than rhs, false otherwise. |
operator >=(LocalTime, LocalTime)
Compares two LocalTime values to see if the left one is later than or equal to the right one.
See the type documentation for a description of ordering semantics.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static bool operator >=(LocalTime lhs, LocalTime rhs)
Parameters
| Type | Name | Description |
|---|---|---|
| LocalTime | lhs | First operand of the comparison |
| LocalTime | rhs | Second operand of the comparison |
Returns
| Type | Description |
|---|---|
| bool | true if the lhs is later than or equal to rhs, false otherwise. |
operator !=(LocalTime, LocalTime)
Compares two local times for inequality.
See the type documentation for a description of equality semantics.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static bool operator !=(LocalTime lhs, LocalTime rhs)
Parameters
| Type | Name | Description |
|---|---|---|
| LocalTime | lhs | The first value to compare |
| LocalTime | rhs | The second value to compare |
Returns
| Type | Description |
|---|---|
| bool | False if the two times are the same; true otherwise |
operator <(LocalTime, LocalTime)
Compares two LocalTime values to see if the left one is strictly earlier than the right one.
See the type documentation for a description of ordering semantics.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static bool operator <(LocalTime lhs, LocalTime rhs)
Parameters
| Type | Name | Description |
|---|---|---|
| LocalTime | lhs | First operand of the comparison |
| LocalTime | rhs | Second operand of the comparison |
Returns
| Type | Description |
|---|---|
| bool | true if the lhs is strictly earlier than rhs, false otherwise. |
operator <=(LocalTime, LocalTime)
Compares two LocalTime values to see if the left one is earlier than or equal to the right one.
See the type documentation for a description of ordering semantics.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static bool operator <=(LocalTime lhs, LocalTime rhs)
Parameters
| Type | Name | Description |
|---|---|---|
| LocalTime | lhs | First operand of the comparison |
| LocalTime | rhs | Second operand of the comparison |
Returns
| Type | Description |
|---|---|
| bool | true if the lhs is earlier than or equal to rhs, false otherwise. |
operator -(LocalTime, LocalTime)
Subtracts one time from another, returning the result as a Period.
Since 2.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static Period operator -(LocalTime lhs, LocalTime rhs)
Parameters
| Type | Name | Description |
|---|---|---|
| LocalTime | lhs | The time to subtract from |
| LocalTime | rhs | The time to subtract |
Returns
| Type | Description |
|---|---|
| Period | The result of subtracting one time from another. |
Remarks
This is simply a convenience operator for calling Between(LocalTime, LocalTime).
operator -(LocalTime, Period)
Creates a new local time by subtracting a period from an existing time. The period must not contain
any date-related units (days etc) with non-zero values.
This is a convenience operator over the Minus(Period) method.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static LocalTime operator -(LocalTime time, Period period)
Parameters
| Type | Name | Description |
|---|---|---|
| LocalTime | time | The time to subtract the period from |
| Period | period | The period to subtract |
Returns
| Type | Description |
|---|---|
| LocalTime | The result of subtract the period from the time, wrapping via midnight if necessary |
Explicit Interface Implementations
IComparable.CompareTo(object?)
Implementation of CompareTo(object) to compare two LocalTimes.
See the type documentation for a description of ordering semantics.
Since 1.1.x
Availability net6.0, net8.0, netstandard2.0
Declaration
int IComparable.CompareTo(object? obj)
Parameters
| Type | Name | Description |
|---|---|---|
| object | obj | The object to compare this value with. |
Returns
| Type | Description |
|---|---|
| int | The result of comparing this LocalTime with another one; see CompareTo(LocalTime) for general details.
If obj is null, this method returns a value greater than 0. |
Remarks
This uses explicit interface implementation to avoid it being called accidentally. The generic implementation should usually be preferred.
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | obj is non-null but does not refer to an instance of LocalTime. |
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 1.2.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 1.2.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. |