Struct LocalDateTime
A date and time in a particular calendar system. A LocalDateTime value does not represent an
instant on the global time line, because it has no associated time zone: "November 12th 2009 7pm, ISO calendar"
occurred at different instants for different people around the world.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Assembly: NodaTime.dll
Syntax
[TypeConverter(typeof(LocalDateTimeTypeConverter))]
public readonly struct LocalDateTime : IEquatable<LocalDateTime>, IComparable<LocalDateTime>, IComparable, IFormattable, IXmlSerializable, IAdditionOperators<LocalDateTime, Period, LocalDateTime>, ISubtractionOperators<LocalDateTime, LocalDateTime, Period>, ISubtractionOperators<LocalDateTime, Period, LocalDateTime>, IComparisonOperators<LocalDateTime, LocalDateTime, bool>, IEqualityOperators<LocalDateTime, LocalDateTime, bool>
Constructors
LocalDateTime(int, int, int, int, int)
Initializes a new instance of the
LocalDateTime struct using the ISO calendar system.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public LocalDateTime(int year, int month, int day, int hour, int minute)
Parameters
Type |
Name |
Description |
int |
year |
The year. This is the "absolute year",
so a value of 0 means 1 BC, for example. |
int |
month |
The month of year. |
int |
day |
The day of month. |
int |
hour |
The hour. |
int |
minute |
The minute. |
Sample snippet
using NodaTime;
using NodaTime.Text;
using System;
LocalDateTime dt = new LocalDateTime(2010, 6, 16, 16, 20);
Console.WriteLine(LocalDateTimePattern.GeneralIso.Format(dt));
Console.WriteLine(dt.Calendar);
Output:
2010-06-16T16:20:00
ISO
Exceptions
LocalDateTime(int, int, int, int, int, CalendarSystem)
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public LocalDateTime(int year, int month, int day, int hour, int minute, CalendarSystem calendar)
Parameters
Type |
Name |
Description |
int |
year |
The year. This is the "absolute year", so, for
the ISO calendar, a value of 0 means 1 BC, for example. |
int |
month |
The month of year. |
int |
day |
The day of month. |
int |
hour |
The hour. |
int |
minute |
The minute. |
CalendarSystem |
calendar |
The calendar. |
Sample snippet
using NodaTime;
using System;
CalendarSystem calendar = CalendarSystem.Iso;
LocalDateTime dt = new LocalDateTime(2010, 6, 16, 16, 20, calendar);
Console.WriteLine(dt.Minute);
Output:
20
Exceptions
LocalDateTime(int, int, int, int, int, int)
Initializes a new instance of the
LocalDateTime struct using the ISO calendar system.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public LocalDateTime(int year, int month, int day, int hour, int minute, int second)
Parameters
Type |
Name |
Description |
int |
year |
The year. This is the "absolute year",
so a value of 0 means 1 BC, for example. |
int |
month |
The month of year. |
int |
day |
The day of month. |
int |
hour |
The hour. |
int |
minute |
The minute. |
int |
second |
The second. |
Exceptions
LocalDateTime(int, int, int, int, int, int, CalendarSystem)
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public LocalDateTime(int year, int month, int day, int hour, int minute, int second, CalendarSystem calendar)
Parameters
Type |
Name |
Description |
int |
year |
The year. This is the "absolute year", so, for
the ISO calendar, a value of 0 means 1 BC, for example. |
int |
month |
The month of year. |
int |
day |
The day of month. |
int |
hour |
The hour. |
int |
minute |
The minute. |
int |
second |
The second. |
CalendarSystem |
calendar |
The calendar. |
Exceptions
LocalDateTime(int, int, int, int, int, int, int)
Initializes a new instance of the
LocalDateTime struct using the ISO calendar system.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public LocalDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond)
Parameters
Type |
Name |
Description |
int |
year |
The year. This is the "absolute year",
so a value of 0 means 1 BC, for example. |
int |
month |
The month of year. |
int |
day |
The day of month. |
int |
hour |
The hour. |
int |
minute |
The minute. |
int |
second |
The second. |
int |
millisecond |
The millisecond. |
Exceptions
LocalDateTime(int, int, int, int, int, int, int, CalendarSystem)
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public LocalDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, CalendarSystem calendar)
Parameters
Type |
Name |
Description |
int |
year |
The year. This is the "absolute year", so, for
the ISO calendar, a value of 0 means 1 BC, for example. |
int |
month |
The month of year. |
int |
day |
The day of month. |
int |
hour |
The hour. |
int |
minute |
The minute. |
int |
second |
The second. |
int |
millisecond |
The millisecond. |
CalendarSystem |
calendar |
The calendar. |
Exceptions
Properties
Calendar
Gets the calendar system associated with this local date and time.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public CalendarSystem Calendar { get; }
Property Value
Type |
Description |
CalendarSystem |
The calendar system associated with this local date and time. |
ClockHourOfHalfDay
Gets the hour of the half-day of this local date and 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 date and time, in the range 1 to 12 inclusive. |
Date
Gets the date portion of this local date and time as a
LocalDate in the same calendar system as this value.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public LocalDate Date { get; }
Property Value
Type |
Description |
LocalDate |
The date portion of this local date and time as a LocalDate in the same calendar system as this value. |
Day
Gets the day of this local date and time within the month.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
Property Value
Type |
Description |
int |
The day of this local date and time within the month. |
DayOfWeek
Gets the week day of this local date and time expressed as an
IsoDayOfWeek value.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public IsoDayOfWeek DayOfWeek { get; }
Property Value
Type |
Description |
IsoDayOfWeek |
The week day of this local date and time expressed as an IsoDayOfWeek . |
DayOfYear
Gets the day of this local date and time within the year.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public int DayOfYear { get; }
Property Value
Type |
Description |
int |
The day of this local date and time within the year. |
Era
Gets the era of this local date and time.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
Property Value
Type |
Description |
Era |
The era of this local date and time. |
Hour
Gets the hour of day of this local date and time, in the range 0 to 23 inclusive.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
Property Value
Type |
Description |
int |
The hour of day of this local date and time, in the range 0 to 23 inclusive. |
MaxIsoValue
The maximum (latest) date and time representable in the ISO calendar system.
This is a nanosecond before midnight at the end of
MaxIsoValue.
Since 3.1.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static LocalDateTime MaxIsoValue { get; }
Property Value
Millisecond
Gets the millisecond of this local date and 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 date and time within the second, in the range 0 to 999 inclusive. |
MinIsoValue
The minimum (earliest) date and time representable in the ISO calendar system.
This is midnight at the start of
MinIsoValue.
Since 3.1.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static LocalDateTime MinIsoValue { get; }
Property Value
Minute
Gets the minute of this local date and 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 date and time, in the range 0 to 59 inclusive. |
Month
Gets the month of this local date and time within the year.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public int Month { get; }
Property Value
Type |
Description |
int |
The month of this local date and time within the year. |
NanosecondOfDay
Gets the nanosecond of this local date and 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 date and 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. |
Second
Gets the second of this local date and 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 date and time within the minute, in the range 0 to 59 inclusive. |
TickOfDay
Gets the tick of this local date and 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 date and 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.
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. |
TimeOfDay
Gets the time portion of this local date and time as a
LocalTime.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public LocalTime TimeOfDay { get; }
Property Value
Type |
Description |
LocalTime |
The time portion of this local date and time as a LocalTime . |
Year
Gets the year of this local date and time.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
Property Value
Type |
Description |
int |
The year of this local date and time. |
YearOfEra
Gets the year of this local date and time within its era.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public int YearOfEra { get; }
Property Value
Type |
Description |
int |
The year of this local date and time within its era. |
Methods
Add(LocalDateTime, Period)
Add the specified period to the date and time.
Fields are added in descending order of significance (years first, then months, and so on).
Friendly alternative to operator+()
.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static LocalDateTime Add(LocalDateTime localDateTime, Period period)
Parameters
Type |
Name |
Description |
LocalDateTime |
localDateTime |
Initial local date and time |
Period |
period |
Period to add |
Returns
AddSchema(XmlSchemaSet)
Adds the XML schema type describing the structure of the
LocalDateTime 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
Returns
Type |
Description |
XmlQualifiedName |
The qualified name of the schema type that was added to the xmlSchemaSet . |
CompareTo(LocalDateTime)
Indicates whether this date/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(LocalDateTime other)
Parameters
Type |
Name |
Description |
LocalDateTime |
other |
The other local date/time to compare with this value. |
Returns
Type |
Description |
int |
A value less than zero if this date/time is earlier than other ;
zero if this date/time is the same as other ; a value greater than zero if this date/time is
later than other . |
Exceptions
Type |
Condition |
ArgumentException |
The calendar system of other is not the
same as the calendar system of this value. |
Deconstruct(out LocalDate, out LocalTime)
Since 2.3.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public void Deconstruct(out LocalDate date, out LocalTime time)
Parameters
Type |
Name |
Description |
LocalDate |
date |
The date portion of the value. |
LocalTime |
time |
The time portion of the value. |
Equals(LocalDateTime)
Indicates whether the current object is equal to another object of the same type.
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(LocalDateTime other)
Parameters
Type |
Name |
Description |
LocalDateTime |
other |
An object to compare with this object. |
Returns
Type |
Description |
bool |
true if the current object is equal to the other parameter; otherwise, false. |
Equals(object?)
Determines whether the specified
object is equal to this instance.
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 with this instance. |
Returns
Type |
Description |
bool |
true if the specified object is equal to this instance;
otherwise, false . |
Overrides
FromDateTime(DateTime)
Converts a
DateTime of any kind to a LocalDateTime in the ISO calendar. This does not perform
any time zone conversions, so a DateTime with a
Kind of
Utc
will still have the same day/hour/minute etc - it won't be converted into the local system time.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static LocalDateTime FromDateTime(DateTime dateTime)
Parameters
Type |
Name |
Description |
DateTime |
dateTime |
Value to convert into a Noda Time local date and time |
Returns
FromDateTime(DateTime, CalendarSystem)
Converts a
DateTime of any kind to a LocalDateTime in the specified calendar. This does not perform
any time zone conversions, so a DateTime with a
Kind of
Utc
will still have the same day/hour/minute etc - it won't be converted into the local system time.
Since 2.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static LocalDateTime FromDateTime(DateTime dateTime, CalendarSystem calendar)
Parameters
Type |
Name |
Description |
DateTime |
dateTime |
Value to convert into a Noda Time local date and time |
CalendarSystem |
calendar |
The calendar system to convert into |
Returns
GetHashCode()
Returns a hash code for this instance.
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 instance, suitable for use in hashing algorithms and data
structures like a hash table. |
Overrides
InUtc()
Returns the mapping of this local date/time within
Utc.
Since 1.1.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public ZonedDateTime InUtc()
Returns
Type |
Description |
ZonedDateTime |
The result of mapping this local date/time in UTC. |
InZone(DateTimeZone, ZoneLocalMappingResolver)
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public ZonedDateTime InZone(DateTimeZone zone, ZoneLocalMappingResolver resolver)
Parameters
Returns
Type |
Description |
ZonedDateTime |
The result of resolving the mapping. |
InZoneLeniently(DateTimeZone)
Returns the mapping of this local date/time within the given
DateTimeZone,
with "lenient" rules applied such that ambiguous values map to the earlier of the alternatives, and
"skipped" values are shifted forward by the duration of the "gap".
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public ZonedDateTime InZoneLeniently(DateTimeZone zone)
Parameters
Type |
Name |
Description |
DateTimeZone |
zone |
The time zone in which to map this local date/time. |
Returns
Type |
Description |
ZonedDateTime |
The result of mapping this local date/time in the given time zone. |
InZoneStrictly(DateTimeZone)
Returns the mapping of this local date/time within the given
DateTimeZone,
with "strict" rules applied such that an exception is thrown if either the mapping is
ambiguous or the time is skipped.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public ZonedDateTime InZoneStrictly(DateTimeZone zone)
Parameters
Type |
Name |
Description |
DateTimeZone |
zone |
The time zone in which to map this local date/time. |
Returns
Type |
Description |
ZonedDateTime |
The result of mapping this local date/time in the given time zone. |
Exceptions
Max(LocalDateTime, LocalDateTime)
Returns the later date/time of the given two.
Since 2.3.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static LocalDateTime Max(LocalDateTime x, LocalDateTime y)
Parameters
Returns
Exceptions
Min(LocalDateTime, LocalDateTime)
Returns the earlier date/time of the given two.
Since 2.3.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static LocalDateTime Min(LocalDateTime x, LocalDateTime y)
Parameters
Returns
Exceptions
Minus(LocalDateTime)
Subtracts the specified date/time from this date/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(LocalDateTime localDateTime)
Parameters
Type |
Name |
Description |
LocalDateTime |
localDateTime |
The date/time to subtract from this |
Returns
Type |
Description |
Period |
The difference between the specified date/time and this one |
Minus(Period)
Subtracts a period from a local date/time.
Fields are subtracted in descending order of significance (years first, then months, and so on).
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public LocalDateTime Minus(Period period)
Parameters
Type |
Name |
Description |
Period |
period |
Period to subtract |
Returns
Next(IsoDayOfWeek)
Returns the next
LocalDateTime falling on the specified
IsoDayOfWeek,
at the same time of day as this value.
This is a strict "next" - if this value on already falls on the target
day of the week, the returned value will be a week later.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public LocalDateTime Next(IsoDayOfWeek targetDayOfWeek)
Parameters
Type |
Name |
Description |
IsoDayOfWeek |
targetDayOfWeek |
The ISO day of the week to return the next date of. |
Returns
Exceptions
Plus(Period)
Adds a period to this local date/time.
Fields are added in descending order of significance (years first, then months, and so on).
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public LocalDateTime Plus(Period period)
Parameters
Type |
Name |
Description |
Period |
period |
Period to add |
Returns
PlusDays(int)
Returns a new LocalDateTime representing the current value with the given number of days added.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public LocalDateTime PlusDays(int days)
Parameters
Type |
Name |
Description |
int |
days |
The number of days to add |
Returns
Type |
Description |
LocalDateTime |
The current value plus the given number of days. |
PlusHours(long)
Returns a new LocalDateTime representing the current value with the given number of hours added.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public LocalDateTime PlusHours(long hours)
Parameters
Type |
Name |
Description |
long |
hours |
The number of hours to add |
Returns
Type |
Description |
LocalDateTime |
The current value plus the given number of hours. |
PlusMilliseconds(long)
Returns a new LocalDateTime representing the current value with the given number of milliseconds added.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public LocalDateTime PlusMilliseconds(long milliseconds)
Parameters
Type |
Name |
Description |
long |
milliseconds |
The number of milliseconds to add |
Returns
Type |
Description |
LocalDateTime |
The current value plus the given number of milliseconds. |
PlusMinutes(long)
Returns a new LocalDateTime representing the current value with the given number of minutes added.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public LocalDateTime PlusMinutes(long minutes)
Parameters
Type |
Name |
Description |
long |
minutes |
The number of minutes to add |
Returns
Type |
Description |
LocalDateTime |
The current value plus the given number of minutes. |
PlusMonths(int)
Returns a new LocalDateTime representing the current value with the given number of months added.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public LocalDateTime PlusMonths(int months)
Parameters
Type |
Name |
Description |
int |
months |
The number of months to add |
Returns
Type |
Description |
LocalDateTime |
The current value plus the given number of months. |
PlusNanoseconds(long)
Returns a new LocalDateTime representing the current value with the given number of nanoseconds added.
Since 2.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public LocalDateTime PlusNanoseconds(long nanoseconds)
Parameters
Type |
Name |
Description |
long |
nanoseconds |
The number of nanoseconds to add |
Returns
Type |
Description |
LocalDateTime |
The current value plus the given number of nanoseconds. |
PlusSeconds(long)
Returns a new LocalDateTime representing the current value with the given number of seconds added.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public LocalDateTime PlusSeconds(long seconds)
Parameters
Type |
Name |
Description |
long |
seconds |
The number of seconds to add |
Returns
Type |
Description |
LocalDateTime |
The current value plus the given number of seconds. |
PlusTicks(long)
Returns a new LocalDateTime representing the current value with the given number of ticks added.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public LocalDateTime PlusTicks(long ticks)
Parameters
Type |
Name |
Description |
long |
ticks |
The number of ticks to add |
Returns
Type |
Description |
LocalDateTime |
The current value plus the given number of ticks. |
PlusWeeks(int)
Returns a new LocalDateTime representing the current value with the given number of weeks added.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public LocalDateTime PlusWeeks(int weeks)
Parameters
Type |
Name |
Description |
int |
weeks |
The number of weeks to add |
Returns
Type |
Description |
LocalDateTime |
The current value plus the given number of weeks. |
PlusYears(int)
Returns a new LocalDateTime representing the current value with the given number of years added.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public LocalDateTime PlusYears(int years)
Parameters
Type |
Name |
Description |
int |
years |
The number of years to add |
Returns
Type |
Description |
LocalDateTime |
The current value plus the given number of years. |
Previous(IsoDayOfWeek)
Returns the previous
LocalDateTime falling on the specified
IsoDayOfWeek,
at the same time of day as this value.
This is a strict "previous" - if this value on already falls on the target
day of the week, the returned value will be a week earlier.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public LocalDateTime Previous(IsoDayOfWeek targetDayOfWeek)
Parameters
Type |
Name |
Description |
IsoDayOfWeek |
targetDayOfWeek |
The ISO day of the week to return the previous date of. |
Returns
Exceptions
Subtract(LocalDateTime, LocalDateTime)
Subtracts one date/time from another, returning the result as a
Period.
Since 2.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static Period Subtract(LocalDateTime lhs, LocalDateTime rhs)
Parameters
Returns
Type |
Description |
Period |
The result of subtracting one date/time from another. |
Subtract(LocalDateTime, Period)
Subtracts the specified period from the date and time. Friendly alternative to operator-()
.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static LocalDateTime Subtract(LocalDateTime localDateTime, Period period)
Parameters
Type |
Name |
Description |
LocalDateTime |
localDateTime |
Initial local date and time |
Period |
period |
Period to subtract |
Returns
ToDateTimeUnspecified()
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public DateTime ToDateTimeUnspecified()
Returns
Type |
Description |
DateTime |
A DateTime value for the same date and time as this value. |
Exceptions
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 ("G"), using the current thread's
culture to obtain a format provider. |
Overrides
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 ("G"). |
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. |
using NodaTime;
using System;
using System.Globalization;
LocalDateTime dt = new LocalDateTime(2010, 6, 16, 16, 20);
Console.WriteLine(dt.ToString("uuuu-MM-dd'T'HH:mm:ss", CultureInfo.InvariantCulture));
Output:
2010-06-16T16:20:00
With(Func<LocalDate, LocalDate>)
Returns this date/time, with the given date adjuster applied to it, maintaining the existing time of day.
Since 2.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public LocalDateTime With(Func<LocalDate, LocalDate> adjuster)
Parameters
Returns
With(Func<LocalTime, LocalTime>)
Returns this date/time, with the given time adjuster applied to it, maintaining the existing date.
Since 2.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public LocalDateTime With(Func<LocalTime, LocalTime> adjuster)
Parameters
Returns
WithCalendar(CalendarSystem)
Creates a new LocalDateTime representing the same physical date and time, but in a different calendar.
The returned LocalDateTime is likely to have different date field values to this one.
For example, January 1st 1970 in the Gregorian calendar was December 19th 1969 in the Julian calendar.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public LocalDateTime WithCalendar(CalendarSystem calendar)
Parameters
Type |
Name |
Description |
CalendarSystem |
calendar |
The calendar system to convert this local date to. |
Returns
WithOffset(Offset)
Returns an
OffsetDateTime for this local date/time with the given offset.
Since 1.1.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public OffsetDateTime WithOffset(Offset offset)
Parameters
Type |
Name |
Description |
Offset |
offset |
The offset to apply. |
Returns
Type |
Description |
OffsetDateTime |
The result of this local date/time offset by the given amount. |
Operators
operator +(LocalDateTime, Period)
Adds a period to a local date/time.
Fields are added in descending order of significance (years first, then months, and so on).
This is a convenience operator over the
Plus(Period) method.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static LocalDateTime operator +(LocalDateTime localDateTime, Period period)
Parameters
Type |
Name |
Description |
LocalDateTime |
localDateTime |
Initial local date and time |
Period |
period |
Period to add |
Returns
operator ==(LocalDateTime, LocalDateTime)
Implements the operator == (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 ==(LocalDateTime left, LocalDateTime right)
Parameters
Type |
Name |
Description |
LocalDateTime |
left |
The left hand side of the operator. |
LocalDateTime |
right |
The right hand side of the operator. |
Returns
Type |
Description |
bool |
true if values are equal to each other, otherwise false . |
operator >(LocalDateTime, LocalDateTime)
Compares two LocalDateTime 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 >(LocalDateTime lhs, LocalDateTime rhs)
Parameters
Returns
Type |
Description |
bool |
true if the lhs is strictly later than rhs , false otherwise. |
Exceptions
Type |
Condition |
ArgumentException |
The calendar system of rhs is not the same
as the calendar of lhs . |
operator >=(LocalDateTime, LocalDateTime)
Compares two LocalDateTime 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 >=(LocalDateTime lhs, LocalDateTime rhs)
Parameters
Returns
Type |
Description |
bool |
true if the lhs is later than or equal to rhs , false otherwise. |
Exceptions
Type |
Condition |
ArgumentException |
The calendar system of rhs is not the same
as the calendar of lhs . |
operator !=(LocalDateTime, LocalDateTime)
Implements the operator != (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 !=(LocalDateTime left, LocalDateTime right)
Parameters
Type |
Name |
Description |
LocalDateTime |
left |
The left hand side of the operator. |
LocalDateTime |
right |
The right hand side of the operator. |
Returns
Type |
Description |
bool |
true if values are not equal to each other, otherwise false . |
operator <(LocalDateTime, LocalDateTime)
Compares two LocalDateTime 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 <(LocalDateTime lhs, LocalDateTime rhs)
Parameters
Returns
Type |
Description |
bool |
true if the lhs is strictly earlier than rhs , false otherwise. |
Exceptions
Type |
Condition |
ArgumentException |
The calendar system of rhs is not the same
as the calendar of lhs . |
operator <=(LocalDateTime, LocalDateTime)
Compares two LocalDateTime 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 <=(LocalDateTime lhs, LocalDateTime rhs)
Parameters
Returns
Type |
Description |
bool |
true if the lhs is earlier than or equal to rhs , false otherwise. |
Exceptions
Type |
Condition |
ArgumentException |
The calendar system of rhs is not the same
as the calendar of lhs . |
operator -(LocalDateTime, LocalDateTime)
Subtracts one date/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 -(LocalDateTime lhs, LocalDateTime rhs)
Parameters
Returns
Type |
Description |
Period |
The result of subtracting one date/time from another. |
operator -(LocalDateTime, Period)
Subtracts a period from a local date/time.
Fields are subtracted in descending order of significance (years first, then months, and so on).
This is a convenience operator over the
Minus(Period) method.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static LocalDateTime operator -(LocalDateTime localDateTime, Period period)
Parameters
Type |
Name |
Description |
LocalDateTime |
localDateTime |
Initial local date and time |
Period |
period |
Period to subtract |
Returns
Explicit Interface Implementations
IComparable.CompareTo(object?)
Implementation of
CompareTo(object) to compare two LocalDateTimes.
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 LocalDateTime with another one; see CompareTo(LocalDateTime) for general details.
If obj is null, this method returns a value greater than 0. |
Exceptions
Type |
Condition |
ArgumentException |
obj is non-null but does not refer to an instance of LocalDateTime,
or refers to a date/time in a different calendar system. |
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
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. |
Implements