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 net35-Client, PCL
Implements
IEquatable<LocalTime>
IComparable<LocalTime>
IFormattable
IComparable
IXmlSerializable
ISerializable
Inherited Members
Object.Equals(Object, Object)
Object.ReferenceEquals(Object, Object)
Object.GetType()
Namespace: NodaTime
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.
Since 1.0.x
Availability net35-Client, PCL
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
Type | Condition |
---|---|
ArgumentOutOfRangeException | The parameters do not form a valid time. |
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.
Since 1.0.x
Availability net35-Client, PCL
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
Type | Condition |
---|---|
ArgumentOutOfRangeException | The parameters do not form a valid time. |
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.
Since 1.0.x
Availability net35-Client, PCL
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
Type | Condition |
---|---|
ArgumentOutOfRangeException | The parameters do not form a valid time. |
LocalTime(Int32, Int32, Int32, Int32, Int32)
Creates a local time at the given hour, minute, second, millisecond and tick within millisecond.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public LocalTime(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. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | The parameters do not form a valid time. |
Fields
Midnight
Local time at midnight, i.e. 0 hours, 0 minutes, 0 seconds.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static readonly LocalTime Midnight
Field Value
Type | Description |
---|---|
LocalTime |
Noon
Local time at noon, i.e. 12 hours, 0 minutes, 0 seconds.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static readonly LocalTime Noon
Field Value
Type | Description |
---|---|
LocalTime |
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 net35-Client, PCL
Declaration
public int ClockHourOfHalfDay { get; }
Property Value
Type | Description |
---|---|
Int32 |
Hour
Gets the hour of day of this local time, in the range 0 to 23 inclusive.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public int Hour { get; }
Property Value
Type | Description |
---|---|
Int32 |
LocalDateTime
Returns a LocalDateTime with this local time, on January 1st 1970 in the ISO
calendar.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public LocalDateTime LocalDateTime { get; }
Property Value
Type | Description |
---|---|
LocalDateTime |
Millisecond
Gets the millisecond of this local time within the second, in the range 0 to 999 inclusive.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public int Millisecond { get; }
Property Value
Type | Description |
---|---|
Int32 |
Minute
Gets the minute of this local time, in the range 0 to 59 inclusive.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public int Minute { get; }
Property Value
Type | Description |
---|---|
Int32 |
Second
Gets the second of this local time within the minute, in the range 0 to 59 inclusive.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public int Second { get; }
Property Value
Type | Description |
---|---|
Int32 |
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 net35-Client, PCL
Declaration
public long TickOfDay { get; }
Property Value
Type | Description |
---|---|
Int64 |
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 net35-Client, PCL
Declaration
public int TickOfSecond { get; }
Property Value
Type | Description |
---|---|
Int32 |
Methods
Add(LocalTime, Period)
Adds the specified period to the time. Friendly alternative to
operator+()
.
Since 1.0.x
Availability net35-Client, PCL
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 |
CompareTo(LocalTime)
Indicates whether this time is earlier, later or the same as another one.
Since 1.0.x
Availability net35-Client, PCL
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.
Since 1.0.x
Availability net35-Client, PCL
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.
Since 1.0.x
Availability net35-Client, PCL
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 is equal to this one; false otherwise |
Overrides
System.ValueType.Equals(System.Object)
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.
Since 1.0.x
Availability net35-Client, PCL
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. |
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. |
FromMillisecondsSinceMidnight(Int32)
Factory method for creating a local time from the number of milliseconds which have elapsed since midnight.
Since 1.1.x
Availability net35-Client, PCL
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.
Since 1.1.x
Availability net35-Client, PCL
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.
Since 1.1.x
Availability net35-Client, PCL
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.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
Int32 | A hash code for this local time. |
Overrides
System.ValueType.GetHashCode()
Minus(Period)
Subtracts the specified period from this time. Fluent alternative to
operator-()
.
Since 1.0.x
Availability net35-Client, PCL
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. |
Plus(Period)
Adds the specified period to this time. Fluent alternative to
operator+()
.
Since 1.0.x
Availability net35-Client, PCL
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(Int64)
Returns a new LocalTime representing the current value with the given number of hours added.
Since 1.0.x
Availability net35-Client, PCL
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. |
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(Int64)
Returns a new LocalTime representing the current value with the given number of milliseconds added.
Since 1.0.x
Availability net35-Client, PCL
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.
Since 1.0.x
Availability net35-Client, PCL
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. |
Remarks
If the value goes past the start or end of the day, it wraps - so 11pm plus 120 minutes is 1am, for example.
PlusSeconds(Int64)
Returns a new LocalTime representing the current value with the given number of seconds added.
Since 1.0.x
Availability net35-Client, PCL
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. |
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(Int64)
Returns a new LocalTime representing the current value with the given number of ticks added.
Since 1.0.x
Availability net35-Client, PCL
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, Period)
Subtracts the specified period from the time. Friendly alternative to
operator-()
.
Since 1.0.x
Availability net35-Client, PCL
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 System.String that represents this instance.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
String | The value of the current instance in the standard format pattern, 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 1.0.x
Availability net35-Client, PCL
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. |
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. |
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.
Since 1.0.x
Availability net35-Client, PCL
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 |
Equality(LocalTime, LocalTime)
Compares two local times for equality, by checking whether they represent
the exact same local time, down to the tick.
Since 1.0.x
Availability net35-Client, PCL
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.
Since 1.0.x
Availability net35-Client, PCL
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.
Since 1.0.x
Availability net35-Client, PCL
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.
Since 1.0.x
Availability net35-Client, PCL
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.
Since 1.0.x
Availability net35-Client, PCL
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.
Since 1.0.x
Availability net35-Client, PCL
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, 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.
Since 1.0.x
Availability net35-Client, PCL
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 System.IComparable.CompareTo(System.Object) to compare two LocalTimes.
Since 1.1.x
Availability net35-Client, PCL
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.
|
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. |
ISerializable.GetObjectData(SerializationInfo, StreamingContext)
Implementation of System.Runtime.Serialization.ISerializable.GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext).
Since 1.2.x
Availability net35-Client
Declaration
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
Parameters
Type | Name | Description |
---|---|---|
SerializationInfo | info | The System.Runtime.Serialization.SerializationInfo to populate with data. |
StreamingContext | context | The destination for this serialization. |
IXmlSerializable.GetSchema()
Since 1.2.x
Availability net35-Client, PCL
Declaration
XmlSchema IXmlSerializable.GetSchema()
Returns
Type | Description |
---|---|
XmlSchema |
IXmlSerializable.ReadXml(XmlReader)
Since 1.2.x
Availability net35-Client, PCL
Declaration
void IXmlSerializable.ReadXml(XmlReader reader)
Parameters
Type | Name | Description |
---|---|---|
XmlReader | reader |
IXmlSerializable.WriteXml(XmlWriter)
Since 1.2.x
Availability net35-Client, PCL
Declaration
void IXmlSerializable.WriteXml(XmlWriter writer)
Parameters
Type | Name | Description |
---|---|---|
XmlWriter | writer |
Implements
System.IEquatable<T>
System.IComparable<T>
System.IFormattable
System.IComparable
System.Xml.Serialization.IXmlSerializable
System.Runtime.Serialization.ISerializable