Noda Time
Show / Hide Table of Contents

Struct LocalDateTime

A date and time in a particular calendar system. A LocalDateTime value does not represent an instant on the 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 net35-Client, PCL
Implements
IEquatable<LocalDateTime>
IComparable<LocalDateTime>
IComparable
IFormattable
IXmlSerializable
ISerializable
Inherited Members
Object.Equals(Object, Object)
Object.ReferenceEquals(Object, Object)
Object.GetType()
Namespace: NodaTime
Assembly: NodaTime.dll
Syntax
[Serializable]
public struct LocalDateTime : IEquatable<LocalDateTime>, IComparable<LocalDateTime>, IComparable, IFormattable, IXmlSerializable, ISerializable
Remarks

This type defaults to using the IsoCalendarSystem unless a different calendar system is specified.

Comparisons of values can be handled in a way which is either calendar-sensitive or calendar-insensitive. Noda Time implements all the operators (and the Equals(LocalDateTime) method) such that all operators other than Inequality(LocalDateTime, LocalDateTime) will return false if asked to compare two values in different calendar systems.

However, the CompareTo(LocalDateTime) method (implementing System.IComparable<T>) is calendar-insensitive; it compares the two values historically in terms of when they actually occurred, as if they're both converted to some "neutral" calendar system first.

It's unclear at the time of this writing whether this is the most appropriate approach, and it may change in future versions. In general, it would be a good idea for users to avoid comparing dates in different calendar systems, and indeed most users are unlikely to ever explicitly consider which calendar system they're working in anyway.

Constructors

LocalDateTime(Int32, Int32, Int32, Int32, Int32)

Initializes a new instance of the LocalDateTime struct using the ISO calendar system.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public LocalDateTime(int year, int month, int day, int hour, int minute)
Parameters
Type Name Description
Int32 year The year. This is the "absolute year", so a value of 0 means 1 BC, for example.
Int32 month The month of year.
Int32 day The day of month.
Int32 hour The hour.
Int32 minute The minute.
Exceptions
Type Condition
ArgumentOutOfRangeException The parameters do not form a valid date/time.

LocalDateTime(Int32, Int32, Int32, Int32, Int32, CalendarSystem)

Initializes a new instance of the LocalDateTime struct.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public LocalDateTime(int year, int month, int day, int hour, int minute, CalendarSystem calendar)
Parameters
Type Name Description
Int32 year The year. This is the "absolute year", so, for the ISO calendar, a value of 0 means 1 BC, for example.
Int32 month The month of year.
Int32 day The day of month.
Int32 hour The hour.
Int32 minute The minute.
CalendarSystem calendar The calendar.
Exceptions
Type Condition
ArgumentOutOfRangeException The parameters do not form a valid date/time.
ArgumentNullException calendar is null.

LocalDateTime(Int32, Int32, Int32, Int32, Int32, Int32)

Initializes a new instance of the LocalDateTime struct using the ISO calendar system.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public LocalDateTime(int year, int month, int day, int hour, int minute, int second)
Parameters
Type Name Description
Int32 year The year. This is the "absolute year", so a value of 0 means 1 BC, for example.
Int32 month The month of year.
Int32 day The day of month.
Int32 hour The hour.
Int32 minute The minute.
Int32 second The second.
Exceptions
Type Condition
ArgumentOutOfRangeException The parameters do not form a valid date/time.

LocalDateTime(Int32, Int32, Int32, Int32, Int32, Int32, CalendarSystem)

Initializes a new instance of the LocalDateTime struct.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public LocalDateTime(int year, int month, int day, int hour, int minute, int second, CalendarSystem calendar)
Parameters
Type Name Description
Int32 year The year. This is the "absolute year", so, for the ISO calendar, a value of 0 means 1 BC, for example.
Int32 month The month of year.
Int32 day The day of month.
Int32 hour The hour.
Int32 minute The minute.
Int32 second The second.
CalendarSystem calendar The calendar.
Exceptions
Type Condition
ArgumentOutOfRangeException The parameters do not form a valid date/time.
ArgumentNullException calendar is null.

LocalDateTime(Int32, Int32, Int32, Int32, Int32, Int32, Int32)

Initializes a new instance of the LocalDateTime struct using the ISO calendar system.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public LocalDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond)
Parameters
Type Name Description
Int32 year The year. This is the "absolute year", so a value of 0 means 1 BC, for example.
Int32 month The month of year.
Int32 day The day of month.
Int32 hour The hour.
Int32 minute The minute.
Int32 second The second.
Int32 millisecond The millisecond.
Exceptions
Type Condition
ArgumentOutOfRangeException The parameters do not form a valid date/time.

LocalDateTime(Int32, Int32, Int32, Int32, Int32, Int32, Int32, CalendarSystem)

Initializes a new instance of the LocalDateTime struct.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public LocalDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, CalendarSystem calendar)
Parameters
Type Name Description
Int32 year The year. This is the "absolute year", so, for the ISO calendar, a value of 0 means 1 BC, for example.
Int32 month The month of year.
Int32 day The day of month.
Int32 hour The hour.
Int32 minute The minute.
Int32 second The second.
Int32 millisecond The millisecond.
CalendarSystem calendar The calendar.
Exceptions
Type Condition
ArgumentOutOfRangeException The parameters do not form a valid date/time.
ArgumentNullException calendar is null.

LocalDateTime(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32)

Initializes a new instance of the LocalDateTime struct.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public LocalDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, int tickWithinMillisecond)
Parameters
Type Name Description
Int32 year The year. This is the "absolute year", so a value of 0 means 1 BC, for example.
Int32 month The month of year.
Int32 day The day of month.
Int32 hour The hour.
Int32 minute The minute.
Int32 second The second.
Int32 millisecond The millisecond.
Int32 tickWithinMillisecond The tick within millisecond.
Exceptions
Type Condition
ArgumentOutOfRangeException The parameters do not form a valid date/time.

LocalDateTime(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, CalendarSystem)

Initializes a new instance of the LocalDateTime struct.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public LocalDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, int tickWithinMillisecond, CalendarSystem calendar)
Parameters
Type Name Description
Int32 year The year. This is the "absolute year", so, for the ISO calendar, a value of 0 means 1 BC, for example.
Int32 month The month of year.
Int32 day The day of month.
Int32 hour The hour.
Int32 minute The minute.
Int32 second The second.
Int32 millisecond The millisecond.
Int32 tickWithinMillisecond The tick within millisecond.
CalendarSystem calendar The calendar.
Exceptions
Type Condition
ArgumentOutOfRangeException The parameters do not form a valid date/time.
ArgumentNullException calendar is null.

Properties

Calendar

Gets the calendar system associated with this local date and time.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public CalendarSystem Calendar { get; }
Property Value
Type Description
CalendarSystem

CenturyOfEra

Gets the century within the era of this local date and time.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public int CenturyOfEra { get; }
Property Value
Type Description
Int32

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 net35-Client, PCL
Declaration
public int ClockHourOfHalfDay { get; }
Property Value
Type Description
Int32

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 net35-Client, PCL
Declaration
public LocalDate Date { get; }
Property Value
Type Description
LocalDate

Day

Gets the day of this local date and time within the month.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public int Day { get; }
Property Value
Type Description
Int32

DayOfWeek

Gets the week day of this local date and time as a number.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public int DayOfWeek { get; }
Property Value
Type Description
Int32
Remarks
For calendars using ISO week days, this gives 1 for Monday to 7 for Sunday.
See Also
IsoDayOfWeek

DayOfYear

Gets the day of this local date and time within the year.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public int DayOfYear { get; }
Property Value
Type Description
Int32

Era

Gets the era of this local date and time.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public Era Era { get; }
Property Value
Type Description
Era

Hour

Gets the hour of day of this local date and 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

IsoDayOfWeek

Gets the week day of this local date and time expressed as an IsoDayOfWeek value, for calendars which use ISO days of the week.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public IsoDayOfWeek IsoDayOfWeek { get; }
Property Value
Type Description
IsoDayOfWeek
Exceptions
Type Condition
System.InvalidOperationException The underlying calendar doesn't use ISO days of the week.
See Also
DayOfWeek

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 net35-Client, PCL
Declaration
public int Millisecond { get; }
Property Value
Type Description
Int32

Minute

Gets the minute of this local date and 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

Month

Gets the month of this local date and time within the year.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public int Month { get; }
Property Value
Type Description
Int32

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 net35-Client, PCL
Declaration
public int Second { get; }
Property Value
Type Description
Int32

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 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

TimeOfDay

Gets the time portion of this local date and time as a LocalTime.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public LocalTime TimeOfDay { get; }
Property Value
Type Description
LocalTime

WeekOfWeekYear

Gets the week within the WeekYear. See WeekYear for more details.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public int WeekOfWeekYear { get; }
Property Value
Type Description
Int32

WeekYear

Gets the "week year" of this local date and time.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public int WeekYear { get; }
Property Value
Type Description
Int32
Remarks

The WeekYear is the year that matches with the WeekOfWeekYear field. In the standard ISO8601 week algorithm, the first week of the year is that in which at least 4 days are in the year. As a result of this definition, day 1 of the first week may be in the previous year. The WeekYear allows you to query the effective year for that day.

For example, January 1st 2011 was a Saturday, so only two days of that week (Saturday and Sunday) were in 2011. Therefore January 1st is part of week 52 of WeekYear 2010. Conversely, December 31st 2012 is a Monday, so is part of week 1 of WeekYear 2013.

Year

Gets the year of this local date and time.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public int Year { get; }
Property Value
Type Description
Int32
Remarks
This returns the "absolute year", so, for the ISO calendar, a value of 0 means 1 BC, for example.

YearOfCentury

Gets the year of this local date and time within its century.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public int YearOfCentury { get; }
Property Value
Type Description
Int32
Remarks
This always returns a value in the range 0 to 99 inclusive.

YearOfEra

Gets the year of this local date and time within its era.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public int YearOfEra { get; }
Property Value
Type Description
Int32

Methods

Add(LocalDateTime, Period)

Add the specified period to the date and time. Friendly alternative to operator+().
Since 1.0.x
Availability net35-Client, PCL
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
Type Description
LocalDateTime The resulting local date and time

CompareTo(LocalDateTime)

Indicates whether this date/time is earlier, later or the same as another one.
Since 1.0.x
Availability net35-Client, PCL
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
Int32 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.
Remarks
The comparison is performed in terms of a calendar-independent notion of dates and times; the calendar systems of both LocalDateTime values are ignored. When both values use the same calendar, this is absolutely natural. However, when comparing a value in one calendar with a value in another, this can lead to surprising results. For example, 1945 in the ISO calendar corresponds to around 1364 in the Islamic calendar, so an Islamic date in year 1400 is "after" a date in 1945 in the ISO calendar.

Equals(LocalDateTime)

Indicates whether the current object is equal to another object of the same type.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public bool Equals(LocalDateTime other)
Parameters
Type Name Description
LocalDateTime other An object to compare with this object.
Returns
Type Description
Boolean true if the current object is equal to the other parameter; otherwise, false.

Equals(Object)

Determines whether the specified System.Object is equal to this instance.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public override bool Equals(object obj)
Parameters
Type Name Description
Object obj The System.Object to compare with this instance.
Returns
Type Description
Boolean true if the specified System.Object is equal to this instance; otherwise, false.
Overrides
System.ValueType.Equals(System.Object)

FromDateTime(DateTime)

Converts a System.DateTime of any kind to a LocalDateTime in the ISO calendar. This does not perform any time zone conversions, so a DateTime with a System.DateTime.Kind of System.DateTimeKind.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 net35-Client, PCL
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
Type Description
LocalDateTime A new LocalDateTime with the same values as the specified DateTime.

GetHashCode()

Returns a hash code for this instance.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public override int GetHashCode()
Returns
Type Description
Int32 A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
Overrides
System.ValueType.GetHashCode()

InUtc()

Returns the mapping of this local date/time within Utc.
Since 1.1.x
Availability net35-Client, PCL
Declaration
public ZonedDateTime InUtc()
Returns
Type Description
ZonedDateTime The result of mapping this local date/time in UTC.
Remarks
As UTC is a fixed time zone, there is no chance that this local date/time is ambiguous or skipped.

InZone(DateTimeZone, ZoneLocalMappingResolver)

Resolves this local date and time into a ZonedDateTime in the given time zone, following the given ZoneLocalMappingResolver to handle ambiguity and skipped times.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public ZonedDateTime InZone(DateTimeZone zone, ZoneLocalMappingResolver resolver)
Parameters
Type Name Description
DateTimeZone zone The time zone to map this local date and time into
ZoneLocalMappingResolver resolver The resolver to apply to the mapping.
Returns
Type Description
ZonedDateTime The result of resolving the mapping.
Remarks
See InZoneStrictly(DateTimeZone) and InZoneLeniently(DateTimeZone) for alternative ways to map a local time to a specific instant. This is a convenience method for calling ResolveLocal(LocalDateTime, ZoneLocalMappingResolver).
Exceptions
Type Condition
ArgumentNullException zone or resolver is null

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 later of the alternatives, and "skipped" values map to the start of the zone interval after the "gap".
Since 1.0.x
Availability net35-Client, PCL
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.
Remarks
See InZoneStrictly(DateTimeZone) and InZone(DateTimeZone, ZoneLocalMappingResolver) for alternative ways to map a local time to a specific instant. This is solely a convenience method for calling AtLeniently(LocalDateTime).
Exceptions
Type Condition
ArgumentNullException zone is null.

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 net35-Client, PCL
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.
Remarks
See InZoneLeniently(DateTimeZone) and InZone(DateTimeZone, ZoneLocalMappingResolver) for alternative ways to map a local time to a specific instant. This is solely a convenience method for calling AtStrictly(LocalDateTime).
Exceptions
Type Condition
SkippedTimeException This local date/time is skipped in the given time zone.
AmbiguousTimeException This local date/time is ambiguous in the given time zone.
ArgumentNullException zone is null.

Minus(Period)

Subtracts a period from a local date/time. Fields are subtracted in the order provided by the period. This is a convenience operator over the Minus(Period) method.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public LocalDateTime Minus(Period period)
Parameters
Type Name Description
Period period Period to subtract
Returns
Type Description
LocalDateTime The resulting local date and time

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 net35-Client, PCL
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
Type Description
LocalDateTime The next LocalDateTime falling on the specified day of the week.
Exceptions
Type Condition
System.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)

Adds a period to this local date/time. Fields are added in the order provided by the period.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public LocalDateTime Plus(Period period)
Parameters
Type Name Description
Period period Period to add
Returns
Type Description
LocalDateTime The resulting local date and time

PlusDays(Int32)

Returns a new LocalDateTime representing the current value with the given number of days added.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public LocalDateTime PlusDays(int days)
Parameters
Type Name Description
Int32 days The number of days to add
Returns
Type Description
LocalDateTime 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 on January 30th will result in a value on February 2nd.

PlusHours(Int64)

Returns a new LocalDateTime representing the current value with the given number of hours added.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public LocalDateTime PlusHours(long hours)
Parameters
Type Name Description
Int64 hours The number of hours to add
Returns
Type Description
LocalDateTime The current value plus the given number of hours.

PlusMilliseconds(Int64)

Returns a new LocalDateTime representing the current value with the given number of milliseconds added.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public LocalDateTime PlusMilliseconds(long milliseconds)
Parameters
Type Name Description
Int64 milliseconds The number of milliseconds to add
Returns
Type Description
LocalDateTime The current value plus the given number of milliseconds.

PlusMinutes(Int64)

Returns a new LocalDateTime representing the current value with the given number of minutes added.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public LocalDateTime PlusMinutes(long minutes)
Parameters
Type Name Description
Int64 minutes The number of minutes to add
Returns
Type Description
LocalDateTime The current value plus the given number of minutes.

PlusMonths(Int32)

Returns a new LocalDateTime representing the current value with the given number of months added.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public LocalDateTime PlusMonths(int months)
Parameters
Type Name Description
Int32 months The number of months to add
Returns
Type Description
LocalDateTime The current value 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.

PlusSeconds(Int64)

Returns a new LocalDateTime representing the current value with the given number of seconds added.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public LocalDateTime PlusSeconds(long seconds)
Parameters
Type Name Description
Int64 seconds The number of seconds to add
Returns
Type Description
LocalDateTime The current value plus the given number of seconds.

PlusTicks(Int64)

Returns a new LocalDateTime representing the current value with the given number of ticks added.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public LocalDateTime PlusTicks(long ticks)
Parameters
Type Name Description
Int64 ticks The number of ticks to add
Returns
Type Description
LocalDateTime The current value plus the given number of ticks.

PlusWeeks(Int32)

Returns a new LocalDateTime representing the current value with the given number of weeks added.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public LocalDateTime PlusWeeks(int weeks)
Parameters
Type Name Description
Int32 weeks The number of weeks to add
Returns
Type Description
LocalDateTime The current value plus the given number of weeks.

PlusYears(Int32)

Returns a new LocalDateTime representing the current value with the given number of years added.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public LocalDateTime PlusYears(int years)
Parameters
Type Name Description
Int32 years The number of years to add
Returns
Type Description
LocalDateTime The current value plus the given number of years.
Remarks
If the resulting date is invalid, lower fields (typically the day of month) are reduced to find a valid value. For example, adding one year to February 29th 2012 will return February 28th 2013; subtracting one year from February 29th 2012 will return February 28th 2011.

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 net35-Client, PCL
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
Type Description
LocalDateTime The previous LocalDateTime falling on the specified day of the week.
Exceptions
Type Condition
System.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(LocalDateTime, Period)

Subtracts the specified period from the date and time. Friendly alternative to operator-().
Since 1.0.x
Availability net35-Client, PCL
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
Type Description
LocalDateTime The resulting local date and time

ToDateTimeUnspecified()

Constructs a System.DateTime from this value which has a System.DateTime.Kind of System.DateTimeKind.Unspecified.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public DateTime ToDateTimeUnspecified()
Returns
Type Description
DateTime A System.DateTime value for the same date and time as this value.
Remarks
System.DateTimeKind.Unspecified is slightly odd - it can be treated as UTC if you use System.DateTime.ToLocalTime or as system local time if you use System.DateTime.ToUniversalTime, but it's the only kind which allows you to construct a System.DateTimeOffset with an arbitrary offset, which makes it as close to the Noda Time non-system-specific "local" concept as exists in .NET.

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 default format pattern ("G"), 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 ("G").
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.

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 net35-Client, PCL
Declaration
public LocalDateTime WithCalendar(CalendarSystem calendarSystem)
Parameters
Type Name Description
CalendarSystem calendarSystem The calendar system to convert this local date to.
Returns
Type Description
LocalDateTime The converted LocalDateTime.
Exceptions
Type Condition
ArgumentNullException calendarSystem is null.

WithOffset(Offset)

Returns an OffsetDateTime for this local date/time with the given offset.
Since 1.1.x
Availability net35-Client, PCL
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.
Remarks
This method is purely a convenient alternative to calling the OffsetDateTime constructor directly.

Operators

Addition(LocalDateTime, Period)

Adds a period to a local date/time. Fields are added in the order provided by the period. This is a convenience operator over the Plus(Period) method.
Since 1.0.x
Availability net35-Client, PCL
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
Type Description
LocalDateTime The resulting local date and time

Equality(LocalDateTime, LocalDateTime)

Implements the operator == (equality).
Since 1.0.x
Availability net35-Client, PCL
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
Boolean true if values are equal to each other, otherwise false.

GreaterThan(LocalDateTime, LocalDateTime)

Compares two LocalDateTime 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>(LocalDateTime lhs, LocalDateTime rhs)
Parameters
Type Name Description
LocalDateTime lhs First operand of the comparison
LocalDateTime rhs Second operand of the comparison
Returns
Type Description
Boolean true if the lhs is strictly later than rhs, false otherwise.
Remarks
This operator always returns false if the two operands have different calendars. See the top-level type documentation for more information about comparisons.

GreaterThanOrEqual(LocalDateTime, LocalDateTime)

Compares two LocalDateTime 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 >=(LocalDateTime lhs, LocalDateTime rhs)
Parameters
Type Name Description
LocalDateTime lhs First operand of the comparison
LocalDateTime rhs Second operand of the comparison
Returns
Type Description
Boolean true if the lhs is later than or equal to rhs, false otherwise.
Remarks
This operator always returns false if the two operands have different calendars. See the top-level type documentation for more information about comparisons.

Inequality(LocalDateTime, LocalDateTime)

Implements the operator != (inequality).
Since 1.0.x
Availability net35-Client, PCL
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
Boolean true if values are not equal to each other, otherwise false.

LessThan(LocalDateTime, LocalDateTime)

Compares two LocalDateTime 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 <(LocalDateTime lhs, LocalDateTime rhs)
Parameters
Type Name Description
LocalDateTime lhs First operand of the comparison
LocalDateTime rhs Second operand of the comparison
Returns
Type Description
Boolean true if the lhs is strictly earlier than rhs, false otherwise.
Remarks
This operator always returns false if the two operands have different calendars. See the top-level type documentation for more information about comparisons.

LessThanOrEqual(LocalDateTime, LocalDateTime)

Compares two LocalDateTime 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 <=(LocalDateTime lhs, LocalDateTime rhs)
Parameters
Type Name Description
LocalDateTime lhs First operand of the comparison
LocalDateTime rhs Second operand of the comparison
Returns
Type Description
Boolean true if the lhs is earlier than or equal to rhs, false otherwise.
Remarks
This operator always returns false if the two operands have different calendars. See the top-level type documentation for more information about comparisons.

Subtraction(LocalDateTime, Period)

Subtracts a period from a local date/time. Fields are subtracted in the order provided by the period. This is a convenience operator over the Minus(Period) method.
Since 1.0.x
Availability net35-Client, PCL
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
Type Description
LocalDateTime The resulting local date and time

Explicit Interface Implementations

IComparable.CompareTo(Object)

Implementation of System.IComparable.CompareTo(System.Object) to compare two LocalDateTimes.
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 LocalDateTime with another one; see CompareTo(LocalDateTime) 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 LocalDateTime.

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
[SecurityCritical]
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.IComparable
System.IFormattable
System.Xml.Serialization.IXmlSerializable
System.Runtime.Serialization.ISerializable
In this article
Back to top Generated by DocFX