Struct LocalTime
LocalTime is an immutable struct representing a time of day, with no reference
to a particular calendar, time zone or date.
Assembly: NodaTime.dll
Syntax
[Serializable]
public struct LocalTime : IEquatable<LocalTime>, IComparable<LocalTime>, IFormattable, IComparable, IXmlSerializable, ISerializable
Constructors
LocalTime(Int32, Int32)
Creates a local time at the given hour and minute, with second, millisecond-of-second
and tick-of-millisecond values of zero.
Declaration
public LocalTime(int hour, int minute)
Parameters
Type |
Name |
Description |
Int32 |
hour |
The hour of day. |
Int32 |
minute |
The minute of the hour. |
Exceptions
LocalTime(Int32, Int32, Int32)
Creates a local time at the given hour, minute and second,
with millisecond-of-second and tick-of-millisecond values of zero.
Declaration
public LocalTime(int hour, int minute, int second)
Parameters
Type |
Name |
Description |
Int32 |
hour |
The hour of day. |
Int32 |
minute |
The minute of the hour. |
Int32 |
second |
The second of the minute. |
Exceptions
LocalTime(Int32, Int32, Int32, Int32)
Creates a local time at the given hour, minute, second and millisecond,
with a tick-of-millisecond value of zero.
Declaration
public LocalTime(int hour, int minute, int second, int millisecond)
Parameters
Type |
Name |
Description |
Int32 |
hour |
The hour of day. |
Int32 |
minute |
The minute of the hour. |
Int32 |
second |
The second of the minute. |
Int32 |
millisecond |
The millisecond of the second. |
Exceptions
Properties
ClockHourOfHalfDay
Gets the hour of the half-day of this local time, in the range 1 to 12 inclusive.
Declaration
public int ClockHourOfHalfDay { get; }
Property Value
Type |
Description |
Int32 |
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.
Declaration
Property Value
Type |
Description |
Int32 |
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.
Declaration
public static LocalTime MaxValue { get; }
Property Value
Midnight
Local time at midnight, i.e. 0 hours, 0 minutes, 0 seconds.
Declaration
public static LocalTime Midnight { get; }
Property Value
Millisecond
Gets the millisecond of this local time within the second, in the range 0 to 999 inclusive.
Declaration
public int Millisecond { get; }
Property Value
Type |
Description |
Int32 |
The millisecond of this local time within the second, in the range 0 to 999 inclusive. |
Minute
Gets the minute of this local time, in the range 0 to 59 inclusive.
Declaration
public int Minute { get; }
Property Value
Type |
Description |
Int32 |
The minute of this local time, in the range 0 to 59 inclusive. |
MinValue
The minimum value of this type; equivalent to
Midnight.
Declaration
public static LocalTime MinValue { get; }
Property Value
NanosecondOfDay
Gets the nanosecond of this local time within the day, in the range 0 to 86,399,999,999,999 inclusive.
Declaration
public long NanosecondOfDay { get; }
Property Value
Type |
Description |
Int64 |
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.
Declaration
public int NanosecondOfSecond { get; }
Property Value
Type |
Description |
Int32 |
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.
Declaration
public static LocalTime Noon { get; }
Property Value
Second
Gets the second of this local time within the minute, in the range 0 to 59 inclusive.
Declaration
public int Second { get; }
Property Value
Type |
Description |
Int32 |
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.
Declaration
public long TickOfDay { get; }
Property Value
Type |
Description |
Int64 |
The tick of this local time within the day, in the range 0 to 863,999,999,999 inclusive. |
TickOfSecond
Gets the tick of this local time within the second, in the range 0 to 9,999,999 inclusive.
Declaration
public int TickOfSecond { get; }
Property Value
Type |
Description |
Int32 |
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+()
.
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 |
Exceptions
CompareTo(LocalTime)
Indicates whether this time is earlier, later or the same as another one.
Declaration
public int CompareTo(LocalTime other)
Parameters
Type |
Name |
Description |
LocalTime |
other |
The other date/time to compare this one with |
Returns
Type |
Description |
Int32 |
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 . |
Equals(LocalTime)
Compares this local time with the specified one for equality,
by checking whether the two values represent the exact same local time, down to the tick.
Declaration
public bool Equals(LocalTime other)
Parameters
Type |
Name |
Description |
LocalTime |
other |
The other local time to compare this one with |
Returns
Type |
Description |
Boolean |
True if the specified time is equal to this one; false otherwise |
Equals(Object)
Compares this local time with the specified reference. A local time is
only equal to another local time with the same underlying tick value.
Declaration
public override bool Equals(object obj)
Parameters
Type |
Name |
Description |
Object |
obj |
The object to compare this one with |
Returns
Type |
Description |
Boolean |
True if the specified value is a local time which is equal to this one; false otherwise |
Overrides
FromHourMinuteSecondMillisecondTick(Int32, Int32, Int32, Int32, Int32)
Factory method to create a local time at the given hour, minute, second, millisecond and tick within millisecond.
Declaration
public static LocalTime FromHourMinuteSecondMillisecondTick(int hour, int minute, int second, int millisecond, int tickWithinMillisecond)
Parameters
Type |
Name |
Description |
Int32 |
hour |
The hour of day. |
Int32 |
minute |
The minute of the hour. |
Int32 |
second |
The second of the minute. |
Int32 |
millisecond |
The millisecond of the second. |
Int32 |
tickWithinMillisecond |
The tick within the millisecond. |
Returns
Type |
Description |
LocalTime |
The resulting time. |
Exceptions
FromHourMinuteSecondNanosecond(Int32, Int32, Int32, Int64)
Factory method for creating a local time from the hour of day, minute of hour, second of minute, and nanosecond of second.
Declaration
public static LocalTime FromHourMinuteSecondNanosecond(int hour, int minute, int second, long nanosecondWithinSecond)
Parameters
Type |
Name |
Description |
Int32 |
hour |
The hour of day in the desired time, in the range [0, 23]. |
Int32 |
minute |
The minute of hour in the desired time, in the range [0, 59]. |
Int32 |
second |
The second of minute in the desired time, in the range [0, 59]. |
Int64 |
nanosecondWithinSecond |
The nanosecond within the second in the desired time, in the range [0, 999999999]. |
Returns
Type |
Description |
LocalTime |
The resulting time. |
Exceptions
FromHourMinuteSecondTick(Int32, Int32, Int32, Int32)
Factory method for creating a local time from the hour of day, minute of hour, second of minute, and tick of second.
Declaration
public static LocalTime FromHourMinuteSecondTick(int hour, int minute, int second, int tickWithinSecond)
Parameters
Type |
Name |
Description |
Int32 |
hour |
The hour of day in the desired time, in the range [0, 23]. |
Int32 |
minute |
The minute of hour in the desired time, in the range [0, 59]. |
Int32 |
second |
The second of minute in the desired time, in the range [0, 59]. |
Int32 |
tickWithinSecond |
The tick within the second in the desired time, in the range [0, 9999999]. |
Returns
Type |
Description |
LocalTime |
The resulting time. |
Exceptions
FromMillisecondsSinceMidnight(Int32)
Factory method for creating a local time from the number of milliseconds which have elapsed since midnight.
Declaration
public static LocalTime FromMillisecondsSinceMidnight(int milliseconds)
Parameters
Type |
Name |
Description |
Int32 |
milliseconds |
The number of milliseconds, in the range [0, 86,399,999] |
Returns
Type |
Description |
LocalTime |
The resulting time. |
FromSecondsSinceMidnight(Int32)
Factory method for creating a local time from the number of seconds which have elapsed since midnight.
Declaration
public static LocalTime FromSecondsSinceMidnight(int seconds)
Parameters
Type |
Name |
Description |
Int32 |
seconds |
The number of seconds, in the range [0, 86,399] |
Returns
Type |
Description |
LocalTime |
The resulting time. |
FromTicksSinceMidnight(Int64)
Factory method for creating a local time from the number of ticks which have elapsed since midnight.
Declaration
public static LocalTime FromTicksSinceMidnight(long ticks)
Parameters
Type |
Name |
Description |
Int64 |
ticks |
The number of ticks, in the range [0, 863,999,999,999] |
Returns
Type |
Description |
LocalTime |
The resulting time. |
GetHashCode()
Returns a hash code for this local time.
Declaration
public override int GetHashCode()
Returns
Type |
Description |
Int32 |
A hash code for this local time. |
Overrides
Minus(LocalTime)
Subtracts the specified time from this time, returning the result as a
Period.
Fluent alternative to
operator-()
.
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 (The value returned is never null.) |
Minus(Period)
Subtracts the specified period from this time. Fluent alternative to operator-()
.
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. |
Exceptions
On(LocalDate)
Declaration
public LocalDateTime On(LocalDate date)
Parameters
Type |
Name |
Description |
LocalDate |
date |
The date to combine with this time |
Returns
Plus(Period)
Adds the specified period to this time. Fluent alternative to operator+()
.
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 |
Exceptions
PlusHours(Int64)
Returns a new LocalTime representing the current value with the given number of hours added.
Declaration
public LocalTime PlusHours(long hours)
Parameters
Type |
Name |
Description |
Int64 |
hours |
The number of hours to add |
Returns
Type |
Description |
LocalTime |
The current value plus the given number of hours. |
PlusMilliseconds(Int64)
Returns a new LocalTime representing the current value with the given number of milliseconds added.
Declaration
public LocalTime PlusMilliseconds(long milliseconds)
Parameters
Type |
Name |
Description |
Int64 |
milliseconds |
The number of milliseconds to add |
Returns
Type |
Description |
LocalTime |
The current value plus the given number of milliseconds. |
PlusMinutes(Int64)
Returns a new LocalTime representing the current value with the given number of minutes added.
Declaration
public LocalTime PlusMinutes(long minutes)
Parameters
Type |
Name |
Description |
Int64 |
minutes |
The number of minutes to add |
Returns
Type |
Description |
LocalTime |
The current value plus the given number of minutes. |
PlusNanoseconds(Int64)
Returns a new LocalTime representing the current value with the given number of nanoseconds added.
Declaration
public LocalTime PlusNanoseconds(long nanoseconds)
Parameters
Type |
Name |
Description |
Int64 |
nanoseconds |
The number of nanoseconds to add |
Returns
Type |
Description |
LocalTime |
The current value plus the given number of ticks. |
PlusSeconds(Int64)
Returns a new LocalTime representing the current value with the given number of seconds added.
Declaration
public LocalTime PlusSeconds(long seconds)
Parameters
Type |
Name |
Description |
Int64 |
seconds |
The number of seconds to add |
Returns
Type |
Description |
LocalTime |
The current value plus the given number of seconds. |
PlusTicks(Int64)
Returns a new LocalTime representing the current value with the given number of ticks added.
Declaration
public LocalTime PlusTicks(long ticks)
Parameters
Type |
Name |
Description |
Int64 |
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.
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. (The value returned is never null.) |
Subtract(LocalTime, Period)
Subtracts the specified period from the time. Friendly alternative to operator-()
.
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. |
Exceptions
ToString()
Returns a
String that represents this instance.
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
Formats the value of the current instance using the specified pattern.
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.
|
With(Func<LocalTime, LocalTime>)
Returns this time, with the given adjuster applied to it.
Declaration
public LocalTime With(Func<LocalTime, LocalTime> adjuster)
Parameters
Returns
Type |
Description |
LocalTime |
The adjusted time. |
Exceptions
Operators
Addition(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.
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 |
Exceptions
Equality(LocalTime, LocalTime)
Compares two local times for equality, by checking whether they represent
the exact same local time, down to the tick.
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 |
Boolean |
True if the two times are the same; false otherwise |
GreaterThan(LocalTime, LocalTime)
Compares two LocalTime values to see if the left one is strictly later than the right
one.
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 |
Boolean |
true if the lhs is strictly later than rhs , false otherwise. |
GreaterThanOrEqual(LocalTime, LocalTime)
Compares two LocalTime values to see if the left one is later than or equal to the right
one.
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 |
Boolean |
true if the lhs is later than or equal to rhs , false otherwise. |
Inequality(LocalTime, LocalTime)
Compares two local times for inequality.
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 |
Boolean |
False if the two times are the same; true otherwise |
LessThan(LocalTime, LocalTime)
Compares two LocalTime values to see if the left one is strictly earlier than the right
one.
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 |
Boolean |
true if the lhs is strictly earlier than rhs , false otherwise. |
LessThanOrEqual(LocalTime, LocalTime)
Compares two LocalTime values to see if the left one is earlier than or equal to the right
one.
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 |
Boolean |
true if the lhs is earlier than or equal to rhs , false otherwise. |
Subtraction(LocalTime, LocalTime)
Subtracts one time from another, returning the result as a
Period.
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. (The value returned is never null.) |
Subtraction(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.
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 |
Exceptions
Explicit Interface Implementations
IComparable.CompareTo(Object)
Declaration
int IComparable.CompareTo(object obj)
Parameters
Type |
Name |
Description |
Object |
obj |
The object to compare this value with. |
Returns
Type |
Description |
Int32 |
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.
|
Exceptions
ISerializable.GetObjectData(SerializationInfo, StreamingContext)
Declaration
[SecurityCritical]
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
Parameters
Exceptions
IXmlSerializable.GetSchema()
Declaration
XmlSchema IXmlSerializable.GetSchema()
Returns
IXmlSerializable.ReadXml(XmlReader)
Declaration
void IXmlSerializable.ReadXml(XmlReader reader)
Parameters
Exceptions
IXmlSerializable.WriteXml(XmlWriter)
Declaration
void IXmlSerializable.WriteXml(XmlWriter writer)
Parameters
Exceptions
Implements