Struct LocalDate
Inherited Members
Namespace: NodaTime
Assembly: NodaTime.dll
Syntax
[TypeConverter(typeof(LocalDateTypeConverter))]
public readonly struct LocalDate : IEquatable<LocalDate>, IComparable<LocalDate>, IComparable, IFormattable, IXmlSerializable
Remarks
Values can freely be compared for equality: a value in a different calendar system is not equal to a value in a different calendar system. However, ordering comparisons (either via the CompareTo(LocalDate) method or via operators) fail with ArgumentException; attempting to compare values in different calendars almost always indicates a bug in the calling code.
The default value of this type is 0001-01-01 (January 1st, 1 C.E.) in the ISO calendar.
Constructors
LocalDate(Era, int, int, int, CalendarSystem)
Declaration
public LocalDate(Era era, int yearOfEra, int month, int day, CalendarSystem calendar)
Parameters
Type | Name | Description |
---|---|---|
Era | era | The era within which to create a date. Must be a valid era within the specified calendar. |
int | yearOfEra | The year of era. |
int | month | The month of year. |
int | day | The day of month. |
CalendarSystem | calendar | Calendar system in which to create the date. |
Remarks
Values can freely be compared for equality: a value in a different calendar system is not equal to a value in a different calendar system. However, ordering comparisons (either via the CompareTo(LocalDate) method or via operators) fail with ArgumentException; attempting to compare values in different calendars almost always indicates a bug in the calling code.
The default value of this type is 0001-01-01 (January 1st, 1 C.E.) in the ISO calendar.
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | The parameters do not form a valid date. |
LocalDate(Era, int, int, int)
Declaration
public LocalDate(Era era, int yearOfEra, int month, int day)
Parameters
Type | Name | Description |
---|---|---|
Era | era | The era within which to create a date. Must be a valid era within the ISO calendar. |
int | yearOfEra | The year of era. |
int | month | The month of year. |
int | day | The day of month. |
Remarks
Values can freely be compared for equality: a value in a different calendar system is not equal to a value in a different calendar system. However, ordering comparisons (either via the CompareTo(LocalDate) method or via operators) fail with ArgumentException; attempting to compare values in different calendars almost always indicates a bug in the calling code.
The default value of this type is 0001-01-01 (January 1st, 1 C.E.) in the ISO calendar.
Sample snippet
using NodaTime;
using NodaTime.Calendars;
using System;
LocalDate date = new LocalDate(Era.BeforeCommon, 2010, 6, 16);
Console.WriteLine(date);
Output:
Sunday, 16 June 2010
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | The parameters do not form a valid date. |
LocalDate(int, int, int, CalendarSystem)
Declaration
public LocalDate(int year, int month, int day, 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. |
CalendarSystem | calendar | Calendar system in which to create the date. |
Remarks
Values can freely be compared for equality: a value in a different calendar system is not equal to a value in a different calendar system. However, ordering comparisons (either via the CompareTo(LocalDate) method or via operators) fail with ArgumentException; attempting to compare values in different calendars almost always indicates a bug in the calling code.
The default value of this type is 0001-01-01 (January 1st, 1 C.E.) in the ISO calendar.
Sample snippet
using NodaTime;
using System;
LocalDate date = new LocalDate(2010, 6, 16, CalendarSystem.Iso);
Console.WriteLine(date);
Output:
Wednesday, 16 June 2010
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | The parameters do not form a valid date. |
LocalDate(int, int, int)
Declaration
public LocalDate(int year, int month, int day)
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. |
Remarks
Values can freely be compared for equality: a value in a different calendar system is not equal to a value in a different calendar system. However, ordering comparisons (either via the CompareTo(LocalDate) method or via operators) fail with ArgumentException; attempting to compare values in different calendars almost always indicates a bug in the calling code.
The default value of this type is 0001-01-01 (January 1st, 1 C.E.) in the ISO calendar.
Sample snippet
using NodaTime;
using System;
using System.Globalization;
LocalDate date = new LocalDate(2010, 6, 16);
Console.WriteLine(date.ToString("uuuu-MM-dd", CultureInfo.InvariantCulture));
Console.WriteLine(date.Year);
Console.WriteLine(date.Month);
Console.WriteLine(date.Day);
Output:
2010-06-16
2010
6
16
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | The parameters do not form a valid date. |
Properties
Calendar
Declaration
public CalendarSystem Calendar { get; }
Property Value
Type | Description |
---|---|
CalendarSystem | The calendar system associated with this local date. |
Remarks
Values can freely be compared for equality: a value in a different calendar system is not equal to a value in a different calendar system. However, ordering comparisons (either via the CompareTo(LocalDate) method or via operators) fail with ArgumentException; attempting to compare values in different calendars almost always indicates a bug in the calling code.
The default value of this type is 0001-01-01 (January 1st, 1 C.E.) in the ISO calendar.
Day
Declaration
public int Day { get; }
Property Value
Type | Description |
---|---|
int | The day of this local date within the month. |
Remarks
Values can freely be compared for equality: a value in a different calendar system is not equal to a value in a different calendar system. However, ordering comparisons (either via the CompareTo(LocalDate) method or via operators) fail with ArgumentException; attempting to compare values in different calendars almost always indicates a bug in the calling code.
The default value of this type is 0001-01-01 (January 1st, 1 C.E.) in the ISO calendar.
Sample snippet
using NodaTime;
using System;
LocalDate date = new LocalDate(2010, 6, 16);
int result = date.Day;
Console.WriteLine(result);
Output:
16
DayOfWeek
Declaration
public IsoDayOfWeek DayOfWeek { get; }
Property Value
Type | Description |
---|---|
IsoDayOfWeek | The week day of this local date expressed as an IsoDayOfWeek . |
Remarks
Values can freely be compared for equality: a value in a different calendar system is not equal to a value in a different calendar system. However, ordering comparisons (either via the CompareTo(LocalDate) method or via operators) fail with ArgumentException; attempting to compare values in different calendars almost always indicates a bug in the calling code.
The default value of this type is 0001-01-01 (January 1st, 1 C.E.) in the ISO calendar.
Sample snippet
using NodaTime;
using System;
LocalDate date = new LocalDate(2010, 6, 16);
IsoDayOfWeek result = date.DayOfWeek;
Console.WriteLine(result);
Output:
Wednesday
DayOfYear
Declaration
public int DayOfYear { get; }
Property Value
Type | Description |
---|---|
int | The day of this local date within the year. |
Remarks
Values can freely be compared for equality: a value in a different calendar system is not equal to a value in a different calendar system. However, ordering comparisons (either via the CompareTo(LocalDate) method or via operators) fail with ArgumentException; attempting to compare values in different calendars almost always indicates a bug in the calling code.
The default value of this type is 0001-01-01 (January 1st, 1 C.E.) in the ISO calendar.
Sample snippet
using NodaTime;
using System;
LocalDate date = new LocalDate(2010, 6, 16);
int result = date.DayOfYear;
Console.WriteLine(result);
Output:
167
Era
Declaration
public Era Era { get; }
Property Value
Type | Description |
---|---|
Era | The era of this local date. |
Remarks
Values can freely be compared for equality: a value in a different calendar system is not equal to a value in a different calendar system. However, ordering comparisons (either via the CompareTo(LocalDate) method or via operators) fail with ArgumentException; attempting to compare values in different calendars almost always indicates a bug in the calling code.
The default value of this type is 0001-01-01 (January 1st, 1 C.E.) in the ISO calendar.
MaxIsoValue
Declaration
public static LocalDate MaxIsoValue { get; }
Property Value
Type | Description |
---|---|
LocalDate |
Remarks
Values can freely be compared for equality: a value in a different calendar system is not equal to a value in a different calendar system. However, ordering comparisons (either via the CompareTo(LocalDate) method or via operators) fail with ArgumentException; attempting to compare values in different calendars almost always indicates a bug in the calling code.
The default value of this type is 0001-01-01 (January 1st, 1 C.E.) in the ISO calendar.
MinIsoValue
Declaration
public static LocalDate MinIsoValue { get; }
Property Value
Type | Description |
---|---|
LocalDate |
Remarks
Values can freely be compared for equality: a value in a different calendar system is not equal to a value in a different calendar system. However, ordering comparisons (either via the CompareTo(LocalDate) method or via operators) fail with ArgumentException; attempting to compare values in different calendars almost always indicates a bug in the calling code.
The default value of this type is 0001-01-01 (January 1st, 1 C.E.) in the ISO calendar.
Month
Declaration
public int Month { get; }
Property Value
Type | Description |
---|---|
int | The month of this local date within the year. |
Remarks
Values can freely be compared for equality: a value in a different calendar system is not equal to a value in a different calendar system. However, ordering comparisons (either via the CompareTo(LocalDate) method or via operators) fail with ArgumentException; attempting to compare values in different calendars almost always indicates a bug in the calling code.
The default value of this type is 0001-01-01 (January 1st, 1 C.E.) in the ISO calendar.
Year
Declaration
public int Year { get; }
Property Value
Type | Description |
---|---|
int | The year of this local date. |
Remarks
YearOfEra
Declaration
public int YearOfEra { get; }
Property Value
Type | Description |
---|---|
int | The year of this local date within the era. |
Remarks
Values can freely be compared for equality: a value in a different calendar system is not equal to a value in a different calendar system. However, ordering comparisons (either via the CompareTo(LocalDate) method or via operators) fail with ArgumentException; attempting to compare values in different calendars almost always indicates a bug in the calling code.
The default value of this type is 0001-01-01 (January 1st, 1 C.E.) in the ISO calendar.
Methods
Add(LocalDate, Period)
operator+()
.
Declaration
public static LocalDate Add(LocalDate date, Period period)
Parameters
Type | Name | Description |
---|---|---|
LocalDate | date | The date to add the period to |
Period | period | The period to add. Must not contain any (non-zero) time units. |
Returns
Type | Description |
---|---|
LocalDate | The sum of the given date and period |
Remarks
Values can freely be compared for equality: a value in a different calendar system is not equal to a value in a different calendar system. However, ordering comparisons (either via the CompareTo(LocalDate) method or via operators) fail with ArgumentException; attempting to compare values in different calendars almost always indicates a bug in the calling code.
The default value of this type is 0001-01-01 (January 1st, 1 C.E.) in the ISO calendar.
Sample snippet
using NodaTime;
using System;
LocalDate date = new LocalDate(2010, 6, 16);
LocalDate result = LocalDate.Add(date, Period.FromDays(3));
Console.WriteLine(result);
Output:
Saturday, 19 June 2010
AddSchema(XmlSchemaSet)
xmlSchemaSet
.
the xmlSchemaSet
.
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 . |
Remarks
Values can freely be compared for equality: a value in a different calendar system is not equal to a value in a different calendar system. However, ordering comparisons (either via the CompareTo(LocalDate) method or via operators) fail with ArgumentException; attempting to compare values in different calendars almost always indicates a bug in the calling code.
The default value of this type is 0001-01-01 (January 1st, 1 C.E.) in the ISO calendar.
At(LocalTime)
operator+()
.
Declaration
public LocalDateTime At(LocalTime time)
Parameters
Type | Name | Description |
---|---|---|
LocalTime | time | The time to combine with this date. |
Returns
Type | Description |
---|---|
LocalDateTime | The LocalDateTime representation of the given time on this date |
Remarks
Values can freely be compared for equality: a value in a different calendar system is not equal to a value in a different calendar system. However, ordering comparisons (either via the CompareTo(LocalDate) method or via operators) fail with ArgumentException; attempting to compare values in different calendars almost always indicates a bug in the calling code.
The default value of this type is 0001-01-01 (January 1st, 1 C.E.) in the ISO calendar.
Sample snippet
using NodaTime;
using System;
LocalDate date = new LocalDate(2010, 6, 16);
LocalTime time = new LocalTime(16, 20);
LocalDateTime dateTime = date.At(time);
Console.WriteLine(dateTime);
Output:
06/16/2010 16:20:00
AtMidnight()
Declaration
public LocalDateTime AtMidnight()
Returns
Type | Description |
---|---|
LocalDateTime | The LocalDateTime representing midnight on this local date, in the same calendar system. |
Remarks
Values can freely be compared for equality: a value in a different calendar system is not equal to a value in a different calendar system. However, ordering comparisons (either via the CompareTo(LocalDate) method or via operators) fail with ArgumentException; attempting to compare values in different calendars almost always indicates a bug in the calling code.
The default value of this type is 0001-01-01 (January 1st, 1 C.E.) in the ISO calendar.
Sample snippet
using NodaTime;
using System;
LocalDate date = new LocalDate(2010, 6, 16);
LocalDateTime dateTime = date.AtMidnight();
Console.WriteLine(dateTime);
Output:
06/16/2010 00:00:00
AtStartOfDayInZone(DateTimeZone)
Declaration
public ZonedDateTime AtStartOfDayInZone(DateTimeZone zone)
Parameters
Type | Name | Description |
---|---|---|
DateTimeZone | zone | The time zone to map this local date into |
Returns
Type | Description |
---|---|
ZonedDateTime | The ZonedDateTime representing the earliest time on this date, in the given time zone. |
Remarks
Exceptions
Type | Condition |
---|---|
SkippedTimeException | The entire day was skipped due to a very large time zone transition. (This is extremely rare.) |
CompareTo(LocalDate)
Declaration
public int CompareTo(LocalDate other)
Parameters
Type | Name | Description |
---|---|---|
LocalDate | other | The other date to compare this one with |
Returns
Type | Description |
---|---|
int | A value less than zero if this date is earlier than other ;
zero if this date is the same as other ; a value greater than zero if this date is
later than other . |
Remarks
Values can freely be compared for equality: a value in a different calendar system is not equal to a value in a different calendar system. However, ordering comparisons (either via the CompareTo(LocalDate) method or via operators) fail with ArgumentException; attempting to compare values in different calendars almost always indicates a bug in the calling code.
The default value of this type is 0001-01-01 (January 1st, 1 C.E.) in the ISO calendar.
Sample snippet
using NodaTime;
using System;
LocalDate date1 = new LocalDate(2010, 6, 16);
LocalDate date2 = new LocalDate(2010, 6, 16);
int result = date1.CompareTo(date2);
Console.WriteLine(result);
Output:
0
Exceptions
Type | Condition |
---|---|
ArgumentException | The calendar system of other is not the
same as the calendar system of this value. |
Deconstruct(out int, out int, out int, out CalendarSystem)
Declaration
public void Deconstruct(out int year, out int month, out int day, out CalendarSystem calendar)
Parameters
Type | Name | Description |
---|---|---|
int | year | The year component of the date. |
int | month | The month component of the date. |
int | day | The day component of the date. |
CalendarSystem | calendar | The CalendarSystem associated with the date. |
Remarks
Values can freely be compared for equality: a value in a different calendar system is not equal to a value in a different calendar system. However, ordering comparisons (either via the CompareTo(LocalDate) method or via operators) fail with ArgumentException; attempting to compare values in different calendars almost always indicates a bug in the calling code.
The default value of this type is 0001-01-01 (January 1st, 1 C.E.) in the ISO calendar.
Deconstruct(out int, out int, out int)
Declaration
public void Deconstruct(out int year, out int month, out int day)
Parameters
Type | Name | Description |
---|---|---|
int | year | The year component of the date. |
int | month | The month component of the date. |
int | day | The day component of the date. |
Remarks
Values can freely be compared for equality: a value in a different calendar system is not equal to a value in a different calendar system. However, ordering comparisons (either via the CompareTo(LocalDate) method or via operators) fail with ArgumentException; attempting to compare values in different calendars almost always indicates a bug in the calling code.
The default value of this type is 0001-01-01 (January 1st, 1 C.E.) in the ISO calendar.
Equals(LocalDate)
Declaration
public bool Equals(LocalDate other)
Parameters
Type | Name | Description |
---|---|---|
LocalDate | other | The value to compare this date with. |
Returns
Type | Description |
---|---|
bool | True if the given value is another local date equal to this one; false otherwise. |
Remarks
Values can freely be compared for equality: a value in a different calendar system is not equal to a value in a different calendar system. However, ordering comparisons (either via the CompareTo(LocalDate) method or via operators) fail with ArgumentException; attempting to compare values in different calendars almost always indicates a bug in the calling code.
The default value of this type is 0001-01-01 (January 1st, 1 C.E.) in the ISO calendar.
Sample snippet
using NodaTime;
using System;
LocalDate date1 = new LocalDate(2010, 6, 16);
LocalDate date2 = new LocalDate(2010, 6, 16);
bool result = date1.Equals(date2);
Console.WriteLine(result);
Output:
True
Equals(object?)
Declaration
public override bool Equals(object? obj)
Parameters
Type | Name | Description |
---|---|---|
object | obj | The object to compare this date with. |
Returns
Type | Description |
---|---|
bool | True if the given value is another local date equal to this one; false otherwise. |
Overrides
Remarks
Values can freely be compared for equality: a value in a different calendar system is not equal to a value in a different calendar system. However, ordering comparisons (either via the CompareTo(LocalDate) method or via operators) fail with ArgumentException; attempting to compare values in different calendars almost always indicates a bug in the calling code.
The default value of this type is 0001-01-01 (January 1st, 1 C.E.) in the ISO calendar.
Sample snippet
using NodaTime;
using System;
LocalDate date = new LocalDate(2010, 6, 16);
object dateAsObject = new LocalDate(2010, 6, 16);
bool result = date.Equals(dateAsObject);
Console.WriteLine(result);
Output:
True
FromDateOnly(DateOnly)
Declaration
public static LocalDate FromDateOnly(DateOnly date)
Parameters
Type | Name | Description |
---|---|---|
DateOnly | date | The date to convert. |
Returns
Type | Description |
---|---|
LocalDate | The LocalDate equivalent, which is always in the ISO calendar system. |
Remarks
Values can freely be compared for equality: a value in a different calendar system is not equal to a value in a different calendar system. However, ordering comparisons (either via the CompareTo(LocalDate) method or via operators) fail with ArgumentException; attempting to compare values in different calendars almost always indicates a bug in the calling code.
The default value of this type is 0001-01-01 (January 1st, 1 C.E.) in the ISO calendar.
FromDateTime(DateTime, CalendarSystem)
Declaration
public static LocalDate FromDateTime(DateTime dateTime, CalendarSystem calendar)
Parameters
Type | Name | Description |
---|---|---|
DateTime | dateTime | Value to convert into a Noda Time local date |
CalendarSystem | calendar | The calendar system to convert into |
Returns
Type | Description |
---|---|
LocalDate | A new LocalDate with the same values as the specified DateTime . |
Remarks
Values can freely be compared for equality: a value in a different calendar system is not equal to a value in a different calendar system. However, ordering comparisons (either via the CompareTo(LocalDate) method or via operators) fail with ArgumentException; attempting to compare values in different calendars almost always indicates a bug in the calling code.
The default value of this type is 0001-01-01 (January 1st, 1 C.E.) in the ISO calendar.
Sample snippet
using NodaTime;
using System;
DateTime earlyJune = new DateTime(2010, 6, 5);
CalendarSystem calendar = CalendarSystem.ForId("Julian");
LocalDate date = LocalDate.FromDateTime(earlyJune, calendar);
// Between the years 2000 and 2099, the Julian calendar is 13 days behind the Gregorian calendar.
Console.WriteLine(date.Year);
Console.WriteLine(date.Month);
Console.WriteLine(date.Day);
Output:
2010
5
23
FromDateTime(DateTime)
Declaration
public static LocalDate FromDateTime(DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
DateTime | dateTime | Value to convert into a Noda Time local date |
Returns
Type | Description |
---|---|
LocalDate | A new LocalDate with the same values as the specified DateTime . |
Remarks
Values can freely be compared for equality: a value in a different calendar system is not equal to a value in a different calendar system. However, ordering comparisons (either via the CompareTo(LocalDate) method or via operators) fail with ArgumentException; attempting to compare values in different calendars almost always indicates a bug in the calling code.
The default value of this type is 0001-01-01 (January 1st, 1 C.E.) in the ISO calendar.
Sample snippet
using NodaTime;
using System;
DateTime earlyJune = new DateTime(2010, 6, 5);
LocalDate date = LocalDate.FromDateTime(earlyJune);
Console.WriteLine(date);
Output:
Saturday, 05 June 2010
FromWeekYearWeekAndDay(int, int, IsoDayOfWeek)
Declaration
public static LocalDate FromWeekYearWeekAndDay(int weekYear, int weekOfWeekYear, IsoDayOfWeek dayOfWeek)
Parameters
Type | Name | Description |
---|---|---|
int | weekYear | ISO-8601 week year of value to return |
int | weekOfWeekYear | ISO-8601 week of week year of value to return |
IsoDayOfWeek | dayOfWeek | ISO-8601 day of week to return |
Returns
Type | Description |
---|---|
LocalDate | The date corresponding to the given week year / week of week year / day of week. |
Remarks
Values can freely be compared for equality: a value in a different calendar system is not equal to a value in a different calendar system. However, ordering comparisons (either via the CompareTo(LocalDate) method or via operators) fail with ArgumentException; attempting to compare values in different calendars almost always indicates a bug in the calling code.
The default value of this type is 0001-01-01 (January 1st, 1 C.E.) in the ISO calendar.
Sample snippet
using NodaTime;
using System;
LocalDate date = LocalDate.FromWeekYearWeekAndDay(2010, 24, IsoDayOfWeek.Wednesday);
Console.WriteLine(date);
Output:
Wednesday, 16 June 2010
FromYearMonthWeekAndDay(int, int, int, IsoDayOfWeek)
Declaration
public static LocalDate FromYearMonthWeekAndDay(int year, int month, int occurrence, IsoDayOfWeek dayOfWeek)
Parameters
Type | Name | Description |
---|---|---|
int | year | The year of the value to return. |
int | month | The month of the value to return. |
int | occurrence | The occurrence of the value to return, which must be in the range [1, 5]. The value 5 can be used to always return the last occurrence of the specified day-of-week, even if there are only 4 occurrences of that day-of-week in the month. |
IsoDayOfWeek | dayOfWeek | The day-of-week of the value to return. |
Returns
Type | Description |
---|---|
LocalDate | The date corresponding to the given year and month, on the given occurrence of the given day of week. |
Remarks
Sample snippet
using NodaTime;
using System;
LocalDate date = LocalDate.FromYearMonthWeekAndDay(2010, 6, 3, IsoDayOfWeek.Wednesday);
Console.WriteLine(date);
Output:
Wednesday, 16 June 2010
GetHashCode()
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
int | A hash code for this local date. |
Overrides
Remarks
Values can freely be compared for equality: a value in a different calendar system is not equal to a value in a different calendar system. However, ordering comparisons (either via the CompareTo(LocalDate) method or via operators) fail with ArgumentException; attempting to compare values in different calendars almost always indicates a bug in the calling code.
The default value of this type is 0001-01-01 (January 1st, 1 C.E.) in the ISO calendar.
Max(LocalDate, LocalDate)
Declaration
public static LocalDate Max(LocalDate x, LocalDate y)
Parameters
Type | Name | Description |
---|---|---|
LocalDate | x | The first date to compare. |
LocalDate | y | The second date to compare. |
Returns
Type | Description |
---|---|
LocalDate | The later date of x or y . |
Remarks
Values can freely be compared for equality: a value in a different calendar system is not equal to a value in a different calendar system. However, ordering comparisons (either via the CompareTo(LocalDate) method or via operators) fail with ArgumentException; attempting to compare values in different calendars almost always indicates a bug in the calling code.
The default value of this type is 0001-01-01 (January 1st, 1 C.E.) in the ISO calendar.
Sample snippet
using NodaTime;
using System;
LocalDate earlyJune = new LocalDate(2010, 6, 5);
LocalDate lateJune = new LocalDate(2010, 6, 25);
LocalDate max = LocalDate.Max(earlyJune, lateJune);
Console.WriteLine(max);
Output:
Friday, 25 June 2010
Exceptions
Type | Condition |
---|---|
ArgumentException | The two dates have different calendar systems. |
Min(LocalDate, LocalDate)
Declaration
public static LocalDate Min(LocalDate x, LocalDate y)
Parameters
Type | Name | Description |
---|---|---|
LocalDate | x | The first date to compare. |
LocalDate | y | The second date to compare. |
Returns
Type | Description |
---|---|
LocalDate | The earlier date of x or y . |
Remarks
Values can freely be compared for equality: a value in a different calendar system is not equal to a value in a different calendar system. However, ordering comparisons (either via the CompareTo(LocalDate) method or via operators) fail with ArgumentException; attempting to compare values in different calendars almost always indicates a bug in the calling code.
The default value of this type is 0001-01-01 (January 1st, 1 C.E.) in the ISO calendar.
Sample snippet
using NodaTime;
using System;
LocalDate earlyJune = new LocalDate(2010, 6, 5);
LocalDate lateJune = new LocalDate(2010, 6, 25);
LocalDate min = LocalDate.Min(earlyJune, lateJune);
Console.WriteLine(min);
Output:
Saturday, 05 June 2010
Exceptions
Type | Condition |
---|---|
ArgumentException | The two dates have different calendar systems. |
Minus(LocalDate)
operator-()
.
Declaration
public Period Minus(LocalDate date)
Parameters
Type | Name | Description |
---|---|---|
LocalDate | date | The date to subtract from this |
Returns
Type | Description |
---|---|
Period | The difference between the specified date and this one |
Remarks
Minus(Period)
operator-()
.
Declaration
public LocalDate Minus(Period period)
Parameters
Type | Name | Description |
---|---|---|
Period | period | The period to subtract. Must not contain any (non-zero) time units. |
Returns
Type | Description |
---|---|
LocalDate | The result of subtracting the given period from this date. |
Remarks
Values can freely be compared for equality: a value in a different calendar system is not equal to a value in a different calendar system. However, ordering comparisons (either via the CompareTo(LocalDate) method or via operators) fail with ArgumentException; attempting to compare values in different calendars almost always indicates a bug in the calling code.
The default value of this type is 0001-01-01 (January 1st, 1 C.E.) in the ISO calendar.
Sample snippet
using NodaTime;
using System;
LocalDate date = new LocalDate(2010, 6, 16).Minus(Period.FromDays(1));
Console.WriteLine(date);
Output:
Tuesday, 15 June 2010
Next(IsoDayOfWeek)
Declaration
public LocalDate Next(IsoDayOfWeek targetDayOfWeek)
Parameters
Type | Name | Description |
---|---|---|
IsoDayOfWeek | targetDayOfWeek | The ISO day of the week to return the next date of. |
Returns
Type | Description |
---|---|
LocalDate | The next LocalDate falling on the specified day of the week. |
Remarks
Values can freely be compared for equality: a value in a different calendar system is not equal to a value in a different calendar system. However, ordering comparisons (either via the CompareTo(LocalDate) method or via operators) fail with ArgumentException; attempting to compare values in different calendars almost always indicates a bug in the calling code.
The default value of this type is 0001-01-01 (January 1st, 1 C.E.) in the ISO calendar.
Sample snippet
using NodaTime;
using System;
LocalDate date = new LocalDate(2010, 6, 16);
LocalDate result = date.Next(IsoDayOfWeek.Thursday);
Console.WriteLine(result);
Output:
Thursday, 17 June 2010
Exceptions
Type | Condition |
---|---|
InvalidOperationException | The underlying calendar doesn't use ISO days of the week. |
ArgumentOutOfRangeException | targetDayOfWeek is not a valid day of the
week (Monday to Sunday). |
Plus(Period)
operator+()
.
Declaration
public LocalDate Plus(Period period)
Parameters
Type | Name | Description |
---|---|---|
Period | period | The period to add. Must not contain any (non-zero) time units. |
Returns
Type | Description |
---|---|
LocalDate | The sum of this date and the given period |
Remarks
Values can freely be compared for equality: a value in a different calendar system is not equal to a value in a different calendar system. However, ordering comparisons (either via the CompareTo(LocalDate) method or via operators) fail with ArgumentException; attempting to compare values in different calendars almost always indicates a bug in the calling code.
The default value of this type is 0001-01-01 (January 1st, 1 C.E.) in the ISO calendar.
Sample snippet
using NodaTime;
using System;
LocalDate date = new LocalDate(2010, 1, 30).Plus(Period.FromMonths(1));
Console.WriteLine(date);
Output:
Sunday, 28 February 2010
PlusDays(int)
Declaration
public LocalDate PlusDays(int days)
Parameters
Type | Name | Description |
---|---|---|
int | days | The number of days to add |
Returns
Type | Description |
---|---|
LocalDate | The current value plus the given number of days. |
Remarks
This method does not try to maintain the month or year of the current value, so adding 3 days to a value of January 30th will result in a value of February 2nd.
PlusMonths(int)
Declaration
public LocalDate PlusMonths(int months)
Parameters
Type | Name | Description |
---|---|---|
int | months | The number of months to add |
Returns
Type | Description |
---|---|
LocalDate | The current date plus the given number of months |
Remarks
This method does not try to maintain the year of the current value, so adding four months to a value in October will result in a value in the following February.
If the resulting date is invalid, the day of month is reduced to find a valid value. For example, adding one month to January 30th 2011 will return February 28th 2011; subtracting one month from March 30th 2011 will return February 28th 2011.
PlusWeeks(int)
Declaration
public LocalDate PlusWeeks(int weeks)
Parameters
Type | Name | Description |
---|---|---|
int | weeks | The number of weeks to add |
Returns
Type | Description |
---|---|
LocalDate | The current value plus the given number of weeks. |
Remarks
Values can freely be compared for equality: a value in a different calendar system is not equal to a value in a different calendar system. However, ordering comparisons (either via the CompareTo(LocalDate) method or via operators) fail with ArgumentException; attempting to compare values in different calendars almost always indicates a bug in the calling code.
The default value of this type is 0001-01-01 (January 1st, 1 C.E.) in the ISO calendar.
PlusYears(int)
Declaration
public LocalDate PlusYears(int years)
Parameters
Type | Name | Description |
---|---|---|
int | years | The number of years to add |
Returns
Type | Description |
---|---|
LocalDate | The current value plus the given number of years. |
Remarks
Previous(IsoDayOfWeek)
Declaration
public LocalDate Previous(IsoDayOfWeek targetDayOfWeek)
Parameters
Type | Name | Description |
---|---|---|
IsoDayOfWeek | targetDayOfWeek | The ISO day of the week to return the previous date of. |
Returns
Type | Description |
---|---|
LocalDate | The previous LocalDate falling on the specified day of the week. |
Remarks
Values can freely be compared for equality: a value in a different calendar system is not equal to a value in a different calendar system. However, ordering comparisons (either via the CompareTo(LocalDate) method or via operators) fail with ArgumentException; attempting to compare values in different calendars almost always indicates a bug in the calling code.
The default value of this type is 0001-01-01 (January 1st, 1 C.E.) in the ISO calendar.
Exceptions
Type | Condition |
---|---|
InvalidOperationException | The underlying calendar doesn't use ISO days of the week. |
ArgumentOutOfRangeException | targetDayOfWeek is not a valid day of the
week (Monday to Sunday). |
Subtract(LocalDate, LocalDate)
Declaration
public static Period Subtract(LocalDate lhs, LocalDate rhs)
Parameters
Type | Name | Description |
---|---|---|
LocalDate | lhs | The date to subtract from |
LocalDate | rhs | The date to subtract |
Returns
Type | Description |
---|---|
Period | The result of subtracting one date from another. |
Remarks
Subtract(LocalDate, Period)
operator-()
.
Declaration
public static LocalDate Subtract(LocalDate date, Period period)
Parameters
Type | Name | Description |
---|---|---|
LocalDate | date | The date to subtract the period from |
Period | period | The period to subtract. Must not contain any (non-zero) time units. |
Returns
Type | Description |
---|---|
LocalDate | The result of subtracting the given period from the date. |
Remarks
Values can freely be compared for equality: a value in a different calendar system is not equal to a value in a different calendar system. However, ordering comparisons (either via the CompareTo(LocalDate) method or via operators) fail with ArgumentException; attempting to compare values in different calendars almost always indicates a bug in the calling code.
The default value of this type is 0001-01-01 (January 1st, 1 C.E.) in the ISO calendar.
Sample snippet
using NodaTime;
using System;
LocalDate date = LocalDate.Subtract(new LocalDate(2010, 2, 28), Period.FromMonths(1));
Console.WriteLine(date);
Output:
Thursday, 28 January 2010
ToDateOnly()
Declaration
public DateOnly ToDateOnly()
Returns
Type | Description |
---|---|
DateOnly | A DateOnly value equivalent to this one. |
Remarks
ToDateTimeUnspecified()
Declaration
public DateTime ToDateTimeUnspecified()
Returns
Type | Description |
---|---|
DateTime | A DateTime value for the same date and time as this value. |
Remarks
Unspecified is slightly odd - it can be treated as UTC if you use ToLocalTime() or as system local time if you use ToUniversalTime(), but it's the only kind which allows you to construct a DateTimeOffset with an arbitrary offset, which makes it as close to the Noda Time non-system-specific "local" concept as exists in .NET.
DateTime uses the Gregorian calendar by definition, so the value is implicitly converted to the Gregorian calendar first. The result will be on the same physical day, but the values returned by the Year/Month/Day properties of the DateTime may not match the Year/Month/Day properties of this value.
ToString()
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
string | The value of the current instance in the default format pattern ("D"), using the current thread's culture to obtain a format provider. |
Overrides
Remarks
Values can freely be compared for equality: a value in a different calendar system is not equal to a value in a different calendar system. However, ordering comparisons (either via the CompareTo(LocalDate) method or via operators) fail with ArgumentException; attempting to compare values in different calendars almost always indicates a bug in the calling code.
The default value of this type is 0001-01-01 (January 1st, 1 C.E.) in the ISO calendar.
ToString(string?, IFormatProvider?)
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 ("D"). |
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. |
Remarks
Values can freely be compared for equality: a value in a different calendar system is not equal to a value in a different calendar system. However, ordering comparisons (either via the CompareTo(LocalDate) method or via operators) fail with ArgumentException; attempting to compare values in different calendars almost always indicates a bug in the calling code.
The default value of this type is 0001-01-01 (January 1st, 1 C.E.) in the ISO calendar.
ToYearMonth()
Declaration
public YearMonth ToYearMonth()
Returns
Type | Description |
---|---|
YearMonth | A year/month value containing this date. |
Remarks
Values can freely be compared for equality: a value in a different calendar system is not equal to a value in a different calendar system. However, ordering comparisons (either via the CompareTo(LocalDate) method or via operators) fail with ArgumentException; attempting to compare values in different calendars almost always indicates a bug in the calling code.
The default value of this type is 0001-01-01 (January 1st, 1 C.E.) in the ISO calendar.
Sample snippet
using NodaTime;
using System;
YearMonth yearMonth = new LocalDate(2010, 6, 16).ToYearMonth();
Console.WriteLine(yearMonth);
Output:
2010-06
With(Func<LocalDate, LocalDate>)
Declaration
public LocalDate With(Func<LocalDate, LocalDate> adjuster)
Parameters
Type | Name | Description |
---|---|---|
Func<LocalDate, LocalDate> | adjuster | The adjuster to apply. |
Returns
Type | Description |
---|---|
LocalDate | The adjusted date. |
Remarks
WithCalendar(CalendarSystem)
Declaration
public LocalDate WithCalendar(CalendarSystem calendar)
Parameters
Type | Name | Description |
---|---|---|
CalendarSystem | calendar | The calendar system to convert this local date to. |
Returns
Type | Description |
---|---|
LocalDate | The converted LocalDate |
Remarks
Values can freely be compared for equality: a value in a different calendar system is not equal to a value in a different calendar system. However, ordering comparisons (either via the CompareTo(LocalDate) method or via operators) fail with ArgumentException; attempting to compare values in different calendars almost always indicates a bug in the calling code.
The default value of this type is 0001-01-01 (January 1st, 1 C.E.) in the ISO calendar.
WithOffset(Offset)
Declaration
public OffsetDate WithOffset(Offset offset)
Parameters
Type | Name | Description |
---|---|---|
Offset | offset | The offset to apply. |
Returns
Type | Description |
---|---|
OffsetDate | The result of this date offset by the given amount. |
Remarks
Operators
operator +(LocalDate, LocalTime)
Declaration
public static LocalDateTime operator +(LocalDate date, LocalTime time)
Parameters
Type | Name | Description |
---|---|---|
LocalDate | date | The date to add the time to |
LocalTime | time | The time to add |
Returns
Type | Description |
---|---|
LocalDateTime | The sum of the given date and time |
Remarks
Values can freely be compared for equality: a value in a different calendar system is not equal to a value in a different calendar system. However, ordering comparisons (either via the CompareTo(LocalDate) method or via operators) fail with ArgumentException; attempting to compare values in different calendars almost always indicates a bug in the calling code.
The default value of this type is 0001-01-01 (January 1st, 1 C.E.) in the ISO calendar.
Sample snippet
using NodaTime;
using System;
LocalDate date = new LocalDate(2010, 6, 16);
LocalTime time = new LocalTime(16, 20);
LocalDateTime dateTime = date + time;
Console.WriteLine(dateTime);
Output:
06/16/2010 16:20:00
operator +(LocalDate, Period)
Declaration
public static LocalDate operator +(LocalDate date, Period period)
Parameters
Type | Name | Description |
---|---|---|
LocalDate | date | The date to add the period to |
Period | period | The period to add. Must not contain any (non-zero) time units. |
Returns
Type | Description |
---|---|
LocalDate | The sum of the given date and period |
Remarks
Values can freely be compared for equality: a value in a different calendar system is not equal to a value in a different calendar system. However, ordering comparisons (either via the CompareTo(LocalDate) method or via operators) fail with ArgumentException; attempting to compare values in different calendars almost always indicates a bug in the calling code.
The default value of this type is 0001-01-01 (January 1st, 1 C.E.) in the ISO calendar.
operator ==(LocalDate, LocalDate)
Declaration
public static bool operator ==(LocalDate lhs, LocalDate rhs)
Parameters
Type | Name | Description |
---|---|---|
LocalDate | lhs | The first value to compare |
LocalDate | rhs | The second value to compare |
Returns
Type | Description |
---|---|
bool | True if the two dates are the same and in the same calendar; false otherwise |
Remarks
Values can freely be compared for equality: a value in a different calendar system is not equal to a value in a different calendar system. However, ordering comparisons (either via the CompareTo(LocalDate) method or via operators) fail with ArgumentException; attempting to compare values in different calendars almost always indicates a bug in the calling code.
The default value of this type is 0001-01-01 (January 1st, 1 C.E.) in the ISO calendar.
operator >(LocalDate, LocalDate)
Declaration
public static bool operator >(LocalDate lhs, LocalDate rhs)
Parameters
Type | Name | Description |
---|---|---|
LocalDate | lhs | First operand of the comparison |
LocalDate | rhs | Second operand of the comparison |
Returns
Type | Description |
---|---|
bool | true if the lhs is strictly later than rhs , false otherwise. |
Remarks
Values can freely be compared for equality: a value in a different calendar system is not equal to a value in a different calendar system. However, ordering comparisons (either via the CompareTo(LocalDate) method or via operators) fail with ArgumentException; attempting to compare values in different calendars almost always indicates a bug in the calling code.
The default value of this type is 0001-01-01 (January 1st, 1 C.E.) in the ISO calendar.
Exceptions
Type | Condition |
---|---|
ArgumentException | The calendar system of rhs is not the same
as the calendar of lhs . |
operator >=(LocalDate, LocalDate)
Declaration
public static bool operator >=(LocalDate lhs, LocalDate rhs)
Parameters
Type | Name | Description |
---|---|---|
LocalDate | lhs | First operand of the comparison |
LocalDate | rhs | Second operand of the comparison |
Returns
Type | Description |
---|---|
bool | true if the lhs is later than or equal to rhs , false otherwise. |
Remarks
Values can freely be compared for equality: a value in a different calendar system is not equal to a value in a different calendar system. However, ordering comparisons (either via the CompareTo(LocalDate) method or via operators) fail with ArgumentException; attempting to compare values in different calendars almost always indicates a bug in the calling code.
The default value of this type is 0001-01-01 (January 1st, 1 C.E.) in the ISO calendar.
Exceptions
Type | Condition |
---|---|
ArgumentException | The calendar system of rhs is not the same
as the calendar of lhs . |
operator !=(LocalDate, LocalDate)
Declaration
public static bool operator !=(LocalDate lhs, LocalDate rhs)
Parameters
Type | Name | Description |
---|---|---|
LocalDate | lhs | The first value to compare |
LocalDate | rhs | The second value to compare |
Returns
Type | Description |
---|---|
bool | False if the two dates are the same and in the same calendar; true otherwise |
Remarks
Values can freely be compared for equality: a value in a different calendar system is not equal to a value in a different calendar system. However, ordering comparisons (either via the CompareTo(LocalDate) method or via operators) fail with ArgumentException; attempting to compare values in different calendars almost always indicates a bug in the calling code.
The default value of this type is 0001-01-01 (January 1st, 1 C.E.) in the ISO calendar.
operator <(LocalDate, LocalDate)
Declaration
public static bool operator <(LocalDate lhs, LocalDate rhs)
Parameters
Type | Name | Description |
---|---|---|
LocalDate | lhs | First operand of the comparison |
LocalDate | rhs | Second operand of the comparison |
Returns
Type | Description |
---|---|
bool | true if the lhs is strictly earlier than rhs , false otherwise. |
Remarks
Values can freely be compared for equality: a value in a different calendar system is not equal to a value in a different calendar system. However, ordering comparisons (either via the CompareTo(LocalDate) method or via operators) fail with ArgumentException; attempting to compare values in different calendars almost always indicates a bug in the calling code.
The default value of this type is 0001-01-01 (January 1st, 1 C.E.) in the ISO calendar.
Exceptions
Type | Condition |
---|---|
ArgumentException | The calendar system of rhs is not the same
as the calendar of lhs . |
operator <=(LocalDate, LocalDate)
Declaration
public static bool operator <=(LocalDate lhs, LocalDate rhs)
Parameters
Type | Name | Description |
---|---|---|
LocalDate | lhs | First operand of the comparison |
LocalDate | rhs | Second operand of the comparison |
Returns
Type | Description |
---|---|
bool | true if the lhs is earlier than or equal to rhs , false otherwise. |
Remarks
Values can freely be compared for equality: a value in a different calendar system is not equal to a value in a different calendar system. However, ordering comparisons (either via the CompareTo(LocalDate) method or via operators) fail with ArgumentException; attempting to compare values in different calendars almost always indicates a bug in the calling code.
The default value of this type is 0001-01-01 (January 1st, 1 C.E.) in the ISO calendar.
Exceptions
Type | Condition |
---|---|
ArgumentException | The calendar system of rhs is not the same
as the calendar of lhs . |
operator -(LocalDate, LocalDate)
Declaration
public static Period operator -(LocalDate lhs, LocalDate rhs)
Parameters
Type | Name | Description |
---|---|---|
LocalDate | lhs | The date to subtract from |
LocalDate | rhs | The date to subtract |
Returns
Type | Description |
---|---|
Period | The result of subtracting one date from another. |
Remarks
Exceptions
Type | Condition |
---|---|
ArgumentException |
lhs and rhs are not in the same calendar system.
|
operator -(LocalDate, Period)
Declaration
public static LocalDate operator -(LocalDate date, Period period)
Parameters
Type | Name | Description |
---|---|---|
LocalDate | date | The date to subtract the period from |
Period | period | The period to subtract. Must not contain any (non-zero) time units. |
Returns
Type | Description |
---|---|
LocalDate | The result of subtracting the given period from the date |
Remarks
Values can freely be compared for equality: a value in a different calendar system is not equal to a value in a different calendar system. However, ordering comparisons (either via the CompareTo(LocalDate) method or via operators) fail with ArgumentException; attempting to compare values in different calendars almost always indicates a bug in the calling code.
The default value of this type is 0001-01-01 (January 1st, 1 C.E.) in the ISO calendar.