Early Preview
This is currently very much a preview. Please feel free to try things out,
but don't be upset if anything is not yet working. Feedback is welcome over on our
GitHub Dicussions page.
struct NodaTime.​LocalTime
Assembly: NodaTime
Implemented Interfaces
- System.​IEquatable`1
- System.​IComparable`1
- System.​IFormattable
- System.​IComparable
- System.​Xml.​Serialization.​IXmlSerializable
- System.​Numerics.​IAdditionOperators`3
- System.​Numerics.​ISubtractionOperators`3
- System.​Numerics.​ISubtractionOperators`3
- System.​Numerics.​IComparisonOperators`3 (Inherits: IEqualityOperators<​NodaTime.​LocalTime, NodaTime.​LocalTime, bool>)
- System.​Numerics.​IMinMaxValue`1
LocalTime is an immutable struct representing a time of day, with no reference to a particular calendar, time zone or date.
Remarks
<para>
Ordering and equality are defined in the natural way, simply comparing the number of "nanoseconds since midnight".
</para> <para>The default value of this type is <see cref="P:NodaTime.LocalTime.Midnight" />.</para>
Properties
public static
LocalTime
Midnight
Local time at midnight, i.e. 0 hours, 0 minutes, 0 seconds.
public static
LocalTime
MinValue
The minimum value of this type; equivalent to <see cref="P:NodaTime.LocalTime.Midnight" /> .
public static
LocalTime
Noon
Local time at noon, i.e. 12 hours, 0 minutes, 0 seconds.
public static
LocalTime
MaxValue
The maximum value of this type, one nanosecond before midnight.
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.
public
int
Hour
Gets the hour of day of this local time, in the range 0 to 23 inclusive.
public
int
ClockHourOfHalfDay
Gets the hour of the half-day of this local time, in the range 1 to 12 inclusive.
public
int
Minute
Gets the minute of this local time, in the range 0 to 59 inclusive.
public
int
Second
Gets the second of this local time within the minute, in the range 0 to 59 inclusive.
public
int
Millisecond
Gets the millisecond of this local time within the second, in the range 0 to 999 inclusive.
public
int
TickOfSecond
Gets the tick of this local time within the second, in the range 0 to 9,999,999 inclusive.
public
long
TickOfDay
Gets 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.
public
int
NanosecondOfSecond
Gets the nanosecond of this local time within the second, in the range 0 to 999,999,999 inclusive.
public
long
NanosecondOfDay
Gets the nanosecond of this local time within the day, in the range 0 to 86,399,999,999,999 inclusive.
Methods
public static
LocalTime
FromHourMinuteSecondMillisecondTick​(int hour,
int minute,
int second,
int millisecond,
int tickWithinMillisecond)
Factory method to create a local time at the given hour, minute, second, millisecond and tick within millisecond.
Returns The resulting time.
hour
The hour of day.
minute
The minute of the hour.
second
The second of the minute.
millisecond
The millisecond of the second.
tickWithinMillisecond
The tick within the millisecond.
public static
LocalTime
FromHourMinuteSecondTick​(int hour,
int minute,
int second,
int tickWithinSecond)
Factory method for creating a local time from the hour of day, minute of hour, second of minute, and tick of second.
Returns The resulting time.
hour
The hour of day in the desired time, in the range [0, 23].
minute
The minute of hour in the desired time, in the range [0, 59].
second
The second of minute in the desired time, in the range [0, 59].
tickWithinSecond
The tick within the second in the desired time, in the range [0, 9999999].
Remarks
This is not a constructor overload as it would have the same signature as the one taking millisecond of second.
public static
LocalTime
FromHourMinuteSecondNanosecond​(int hour,
int minute,
int second,
long nanosecondWithinSecond)
Factory method for creating a local time from the hour of day, minute of hour, second of minute, and nanosecond of second.
Returns The resulting time.
hour
The hour of day in the desired time, in the range [0, 23].
minute
The minute of hour in the desired time, in the range [0, 59].
second
The second of minute in the desired time, in the range [0, 59].
nanosecondWithinSecond
The nanosecond within the second in the desired time, in the range [0, 999999999].
Remarks
This is not a constructor overload as it would have the same signature as the one taking millisecond of second.
public static
LocalTime
FromNanosecondsSinceMidnight​(long nanoseconds)
Factory method for creating a local time from the number of nanoseconds which have elapsed since midnight.
Returns The resulting time.
nanoseconds
The number of nanoseconds, in the range [0, 86,399,999,999,999]
public static
LocalTime
FromTicksSinceMidnight​(long ticks)
Factory method for creating a local time from the number of ticks which have elapsed since midnight.
Returns The resulting time.
ticks
The number of ticks, in the range [0, 863,999,999,999]
public static
LocalTime
FromMillisecondsSinceMidnight​(int milliseconds)
Factory method for creating a local time from the number of milliseconds which have elapsed since midnight.
Returns The resulting time.
milliseconds
The number of milliseconds, in the range [0, 86,399,999]
public static
LocalTime
FromSecondsSinceMidnight​(int seconds)
Factory method for creating a local time from the number of seconds which have elapsed since midnight.
Returns The resulting time.
seconds
The number of seconds, in the range [0, 86,399]
public static
LocalTime
FromMinutesSinceMidnight​(int minutes)
Factory method for creating a local time from the number of minutes which have elapsed since midnight.
Returns The resulting time.
minutes
The number of minutes, in the range [0, 1439]
public static
LocalTime
FromHoursSinceMidnight​(int hours)
Factory method for creating a local time from the number of hours which have elapsed since midnight.
Returns The resulting time.
hours
The number of hours, in the range [0, 23]
public static
LocalTime
Add​(LocalTime time,
Period period)
Adds the specified period to the time. Friendly alternative to <c>operator+()</c> .
Returns The sum of the given time and period
time
The time to add the period to
period
The period to add. Must not contain any (non-zero) date units.
public
LocalTime
Plus​(Period period)
Adds the specified period to this time. Fluent alternative to <c>operator+()</c> .
Returns The sum of this time and the given period
period
The period to add. Must not contain any (non-zero) date units.
public static
LocalTime
Subtract​(LocalTime time,
Period period)
Subtracts the specified period from the time. Friendly alternative to <c>operator-()</c> .
Returns The result of subtracting the given period from the time.
time
The time to subtract the period from
period
The period to subtract. Must not contain any (non-zero) date units.
public
LocalTime
Minus​(Period period)
Subtracts the specified period from this time. Fluent alternative to <c>operator-()</c> .
Returns The result of subtracting the given period from this time.
period
The period to subtract. Must not contain any (non-zero) date units.
public static
Period
Subtract​(LocalTime lhs,
LocalTime rhs)
Subtracts one time from another, returning the result as a <see cref="T:NodaTime.Period" /> with units of years, months and days.
Returns The result of subtracting one time from another.
lhs
The time to subtract from
rhs
The time to subtract
Remarks
This is simply a convenience method for calling <see cref="M:NodaTime.Period.Between(NodaTime.LocalTime,NodaTime.LocalTime)" /> .
public
Period
Minus​(LocalTime time)
Subtracts the specified time from this time, returning the result as a <see cref="T:NodaTime.Period" /> .
Fluent alternative to <c>operator-()</c> .
Returns The difference between the specified time and this one
time
The time to subtract from this
public
int
CompareTo​(LocalTime other)
Indicates whether this time is earlier, later or the same as another one.
See the type documentation for a description of ordering semantics.
Returns A value less than zero if this time is earlier than <paramref name="other" /> ;
zero if this time is the same as <paramref name="other" /> ; a value greater than zero if this time is
later than <paramref name="other" /> .
other
The other date/time to compare this one with
public
int
GetHashCode​()
Returns a hash code for this local time.
See the type documentation for a description of equality semantics.
Returns A hash code for this local time.
public
bool
Equals​(LocalTime other)
Compares this local time with the specified one for equality.
See the type documentation for a description of equality semantics.
Returns True if the specified time is equal to this one; false otherwise
other
The other local time to compare this one with
public
bool
Equals​(object obj)
Compares this local time with the specified reference.
See the type documentation for a description of equality semantics.
Returns True if the specified value is a local time which is equal to this one; false otherwise
obj
The object to compare this one with
public
LocalTime
PlusHours​(long hours)
Returns a new LocalTime representing the current value with the given number of hours added.
Returns The current value plus the given number of hours.
hours
The number of hours to add
Remarks
If the value goes past the start or end of the day, it wraps - so 11pm plus two hours is 1am, for example.
public
LocalTime
PlusMinutes​(long minutes)
Returns a new LocalTime representing the current value with the given number of minutes added.
Returns The current value plus the given number of minutes.
minutes
The number of minutes to add
Remarks
If the value goes past the start or end of the day, it wraps - so 11pm plus 120 minutes is 1am, for example.
public
LocalTime
PlusSeconds​(long seconds)
Returns a new LocalTime representing the current value with the given number of seconds added.
Returns The current value plus the given number of seconds.
seconds
The number of seconds to add
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.
public
LocalTime
PlusMilliseconds​(long milliseconds)
Returns a new LocalTime representing the current value with the given number of milliseconds added.
Returns The current value plus the given number of milliseconds.
milliseconds
The number of milliseconds to add
public
LocalTime
PlusTicks​(long ticks)
Returns a new LocalTime representing the current value with the given number of ticks added.
Returns The current value plus the given number of ticks.
ticks
The number of ticks to add
public
LocalTime
PlusNanoseconds​(long nanoseconds)
Returns a new LocalTime representing the current value with the given number of nanoseconds added.
Returns The current value plus the given number of ticks.
nanoseconds
The number of nanoseconds to add
public
LocalTime
With​(System.​Func<​LocalTime, LocalTime> adjuster)
Returns this time, with the given adjuster applied to it.
Returns The adjusted time.
adjuster
The adjuster to apply.
Remarks
If the adjuster attempts to construct an invalid time, any exception thrown by
that construction attempt will be propagated through this method.
public
OffsetTime
WithOffset​(Offset offset)
Returns an <see cref="T:NodaTime.OffsetTime" /> for this time-of-day with the given offset.
Returns The result of this time-of-day offset by the given amount.
offset
The offset to apply.
Remarks
This method is purely a convenient alternative to calling the <see cref="T:NodaTime.OffsetTime" /> constructor directly.
public
LocalDateTime
On​(LocalDate date)
Combines this <see cref="T:NodaTime.LocalTime" /> with the given <see cref="T:NodaTime.LocalDate" />
into a single <see cref="T:NodaTime.LocalDateTime" /> .
Fluent alternative to <c>operator+()</c> .
Returns The <see cref="T:NodaTime.LocalDateTime" /> representation of the given time on this date
date
The date to combine with this time
public
void
Deconstruct​(System.​Int32& hour,
System.​Int32& minute,
System.​Int32& second)
public static
LocalTime
Max​(LocalTime x,
LocalTime y)
Returns the later time of the given two.
Returns The later instant of <paramref name="x" /> or <paramref name="y" /> .
x
The first time to compare.
y
The second time to compare.
public static
LocalTime
Min​(LocalTime x,
LocalTime y)
Returns the earlier time of the given two.
Returns The earlier time of <paramref name="x" /> or <paramref name="y" /> .
x
The first time to compare.
y
The second time to compare.
public
string
ToString​()
Returns a <see cref="T:System.String" /> that represents this instance.
Returns The value of the current instance in the default format pattern ("T"), using the current thread's
culture to obtain a format provider.
public
string
ToString​(string patternText,
System.​IFormatProvider formatProvider)
Formats the value of the current instance using the specified pattern.
Returns A <see cref="T:System.String" /> containing the value of the current instance in the specified format.
patternText
The <see cref="T:System.String" /> specifying the pattern to use,
or null to use the default format pattern ("T").
formatProvider
The <see cref="T:System.IFormatProvider" /> to use when formatting the value,
or null to use the current thread's culture to obtain a format provider.
AddSchema​(System.​Xml.​Schema.​XmlSchemaSet xmlSchemaSet)
Adds the XML schema type describing the structure of the <see cref="T:NodaTime.LocalTime" /> XML serialization to the given <paramref name="xmlSchemaSet" /> .
the <paramref name="xmlSchemaSet" /> .
Returns The qualified name of the schema type that was added to the <paramref name="xmlSchemaSet" /> .
xmlSchemaSet
The XML schema set provided by <see cref="T:System.Xml.Serialization.XmlSchemaExporter" /> .
ToTimeOnly​()
Converts this value to an equivalent <see cref="T:System.TimeOnly" /> .
Returns A <see cref="T:System.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.
public static
LocalTime
FromTimeOnly​(System.​TimeOnly time)
Constructs a <see cref="T:NodaTime.LocalTime" /> from a <see cref="T:System.TimeOnly" /> .
Returns The <see cref="T:NodaTime.LocalTime" /> equivalent.
time
The time of day to convert.
protected
void
Finalize​()
Inherited from object
protected
object
MemberwiseClone​()
Inherited from object