Early Preview
This is currently very much a preview. Please feel free to try things out,
but don't be upset if anything is not yet working. Feedback is welcome over on our
GitHub Dicussions page.
struct NodaTime.​LocalDateTime
Assembly: NodaTime
Implemented Interfaces
- System.​IEquatable`1
- System.​IComparable`1
- System.​IComparable
- System.​IFormattable
- System.​Xml.​Serialization.​IXmlSerializable
- System.​Numerics.​IAdditionOperators`3
- System.​Numerics.​ISubtractionOperators`3
- System.​Numerics.​ISubtractionOperators`3
- System.​Numerics.​IComparisonOperators`3 (Inherits: IEqualityOperators<​NodaTime.​LocalDateTime, NodaTime.​LocalDateTime, bool>)
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.
Remarks
<para>
This type defaults to using the ISO calendar system unless a different calendar system is
specified.
</para> <para>
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 <see cref="M:NodaTime.LocalDateTime.CompareTo(NodaTime.LocalDateTime)" /> method
or via operators) fail with <see cref="T:System.ArgumentException" />; attempting to compare values in different calendars
almost always indicates a bug in the calling code.
</para> <para>The default value of this type is 0001-01-01T00:00:00 (midnight on January 1st, 1 C.E.) in the ISO calendar.</para>
Properties
public static
LocalDateTime
MaxIsoValue
The maximum (latest) date and time representable in the ISO calendar system.
This is a nanosecond before midnight at the end of <see cref="P:NodaTime.LocalDate.MaxIsoValue" /> .
public static
LocalDateTime
MinIsoValue
The minimum (earliest) date and time representable in the ISO calendar system.
This is midnight at the start of <see cref="P:NodaTime.LocalDate.MinIsoValue" /> .
public
CalendarSystem
Calendar
Gets the calendar system associated with this local date and time.
public
int
Year
Gets the year of this local date and time.
Remarks This returns the "absolute year", so, for the ISO calendar,
a value of 0 means 1 BC, for example.
public
int
YearOfEra
Gets the year of this local date and time within its era.
public
Era
Era
Gets the era of this local date and time.
public
int
Month
Gets the month of this local date and time within the year.
public
int
DayOfYear
Gets the day of this local date and time within the year.
public
int
Day
Gets the day of this local date and time within the month.
public
IsoDayOfWeek
DayOfWeek
Gets the week day of this local date and time expressed as an <see cref="T:NodaTime.IsoDayOfWeek" /> value.
public
int
Hour
Gets the hour of day of this local date and time, in the range 0 to 23 inclusive.
public
int
ClockHourOfHalfDay
Gets the hour of the half-day of this local date and time, in the range 1 to 12 inclusive.
public
int
Minute
Gets the minute of this local date and time, in the range 0 to 59 inclusive.
public
int
Second
Gets the second of this local date and time within the minute, in the range 0 to 59 inclusive.
public
int
Millisecond
Gets the millisecond of this local date and time within the second, in the range 0 to 999 inclusive.
public
int
TickOfSecond
Gets the tick of this local time within the second, in the range 0 to 9,999,999 inclusive.
public
long
TickOfDay
Gets the tick of this local date and time within the day, in the range 0 to 863,999,999,999 inclusive.
public
int
NanosecondOfSecond
Gets the nanosecond of this local time within the second, in the range 0 to 999,999,999 inclusive.
public
long
NanosecondOfDay
Gets the nanosecond of this local date and time within the day, in the range 0 to 86,399,999,999,999 inclusive.
public
LocalTime
TimeOfDay
Gets the time portion of this local date and time as a <see cref="T:NodaTime.LocalTime" /> .
public
LocalDate
Date
Gets the date portion of this local date and time as a <see cref="T:NodaTime.LocalDate" /> in the same calendar system as this value.
Methods
ToDateTimeUnspecified​()
Constructs a <see cref="T:System.DateTime" /> from this value which has a <see cref="P:System.DateTime.Kind" />
of <see cref="F:System.DateTimeKind.Unspecified" /> .
Returns A <see cref="T:System.DateTime" /> value for the same date and time as this value.
Remarks
<para>
<see cref="F:System.DateTimeKind.Unspecified" /> is slightly odd - it can be treated as UTC if you use <see cref="M:System.DateTime.ToLocalTime" />
or as system local time if you use <see cref="M:System.DateTime.ToUniversalTime" />, but it's the only kind which allows
you to construct a <see cref="T:System.DateTimeOffset" /> with an arbitrary offset, which makes it as close to
the Noda Time non-system-specific "local" concept as exists in .NET.
</para> <para>
If the date and time is not on a tick boundary (the unit of granularity of DateTime) the value will be truncated
towards the start of time.
</para> <para>
<see cref="T:System.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 <see cref="T:System.DateTime" /> may not
match the Year/Month/Day properties of this value.
</para>
public static
LocalDateTime
FromDateTime​(System.​DateTime dateTime)
Converts a <see cref="T: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 <see cref="P:System.DateTime.Kind" /> of <see cref="F:System.DateTimeKind.Utc" />
will still have the same day/hour/minute etc - it won't be converted into the local system time.
Returns A new <see cref="T:NodaTime.LocalDateTime" /> with the same values as the specified <c>DateTime</c> .
dateTime
Value to convert into a Noda Time local date and time
public static
LocalDateTime
FromDateTime​(System.​DateTime dateTime,
CalendarSystem calendar)
Converts a <see cref="T:System.DateTime" /> of any kind to a LocalDateTime in the specified calendar. This does not perform
any time zone conversions, so a DateTime with a <see cref="P:System.DateTime.Kind" /> of <see cref="F:System.DateTimeKind.Utc" />
will still have the same day/hour/minute etc - it won't be converted into the local system time.
Returns A new <see cref="T:NodaTime.LocalDateTime" /> with the same values as the specified <c>DateTime</c> .
dateTime
Value to convert into a Noda Time local date and time
calendar
The calendar system to convert into
public
bool
Equals​(LocalDateTime other)
Indicates whether the current object is equal to another object of the same type.
See the type documentation for a description of equality semantics.
Returns true if the current object is equal to the <paramref name="other" /> parameter; otherwise, false.
other
An object to compare with this object.
public
int
CompareTo​(LocalDateTime other)
Indicates whether this date/time is earlier, later or the same as another one.
See the type documentation for a description of ordering semantics.
Returns A value less than zero if this date/time is earlier than <paramref name="other" /> ;
zero if this date/time is the same as <paramref name="other" /> ; a value greater than zero if this date/time is
later than <paramref name="other" /> .
other
The other local date/time to compare with this value.
public static
LocalDateTime
Add​(LocalDateTime localDateTime,
Period 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 <c>operator+()</c> .
Returns The resulting local date and time
localDateTime
Initial local date and time
period
Period to add
public
LocalDateTime
Plus​(Period period)
Adds a period to this local date/time.
Fields are added in descending order of significance (years first, then months, and so on).
Returns The resulting local date and time
period
Period to add
public static
LocalDateTime
Subtract​(LocalDateTime localDateTime,
Period period)
Subtracts the specified period from the date and time. Friendly alternative to <c>operator-()</c> .
Returns The resulting local date and time
localDateTime
Initial local date and time
period
Period to subtract
public
LocalDateTime
Minus​(Period period)
Subtracts a period from a local date/time.
Fields are subtracted in descending order of significance (years first, then months, and so on).
Returns The resulting local date and time
period
Period to subtract
public static
Period
Subtract​(LocalDateTime lhs,
LocalDateTime rhs)
Subtracts one date/time from another, returning the result as a <see cref="T:NodaTime.Period" /> .
Returns The result of subtracting one date/time from another.
lhs
The date/time to subtract from
rhs
The date/time to subtract
Remarks
This is simply a convenience method for calling <see cref="M:NodaTime.Period.Between(NodaTime.LocalDateTime,NodaTime.LocalDateTime)" /> .
The calendar systems of the two date/times must be the same.
public
Period
Minus​(LocalDateTime localDateTime)
Subtracts the specified date/time from this date/time, returning the result as a <see cref="T:NodaTime.Period" /> .
Fluent alternative to <c>operator-()</c> .
Returns The difference between the specified date/time and this one
localDateTime
The date/time to subtract from this
Remarks
The specified date/time must be in the same calendar system as this.
public
bool
Equals​(object obj)
Determines whether the specified <see cref="T:System.Object" /> is equal to this instance.
See the type documentation for a description of equality semantics.
Returns <c>true</c> if the specified <see cref="T:System.Object" /> is equal to this instance;
otherwise, <c>false</c> .
obj
The <see cref="T:System.Object" /> to compare with this instance.
public
int
GetHashCode​()
Returns a hash code for this instance.
See the type documentation for a description of equality semantics.
Returns A hash code for this instance, suitable for use in hashing algorithms and data
structures like a hash table.
public
LocalDateTime
With​(System.​Func<​LocalDate, LocalDate> adjuster)
Returns this date/time, with the given date adjuster applied to it, maintaining the existing time of day.
Returns The adjusted date/time.
adjuster
The adjuster to apply.
Remarks
If the adjuster attempts to construct an
invalid date (such as by trying to set a day-of-month of 30 in February), any exception thrown by
that construction attempt will be propagated through this method.
public
LocalDateTime
With​(System.​Func<​LocalTime, LocalTime> adjuster)
Returns this date/time, with the given time adjuster applied to it, maintaining the existing date.
Returns The adjusted date/time.
adjuster
The adjuster to apply.
Remarks
If the adjuster attempts to construct an invalid time, any exception thrown by
that construction attempt will be propagated through this method.
public
LocalDateTime
WithCalendar​(CalendarSystem calendar)
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.
Returns The converted LocalDateTime.
calendar
The calendar system to convert this local date to.
public
LocalDateTime
PlusYears​(int years)
Returns a new LocalDateTime representing the current value with the given number of years added.
Returns The current value plus the given number of years.
years
The number of years to add
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.
public
LocalDateTime
PlusMonths​(int months)
Returns a new LocalDateTime representing the current value with the given number of months added.
Returns The current value plus the given number of months.
months
The number of months to add
Remarks
<para>
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.
</para> <para>
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.
</para>
public
LocalDateTime
PlusDays​(int days)
Returns a new LocalDateTime representing the current value with the given number of days added.
Returns The current value plus the given number of days.
days
The number of days to add
Remarks
<para>
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.
</para>
public
LocalDateTime
PlusWeeks​(int weeks)
Returns a new LocalDateTime representing the current value with the given number of weeks added.
Returns The current value plus the given number of weeks.
weeks
The number of weeks to add
public
LocalDateTime
PlusHours​(long hours)
Returns a new LocalDateTime representing the current value with the given number of hours added.
Returns The current value plus the given number of hours.
hours
The number of hours to add
public
LocalDateTime
PlusMinutes​(long minutes)
Returns a new LocalDateTime representing the current value with the given number of minutes added.
Returns The current value plus the given number of minutes.
minutes
The number of minutes to add
public
LocalDateTime
PlusSeconds​(long seconds)
Returns a new LocalDateTime representing the current value with the given number of seconds added.
Returns The current value plus the given number of seconds.
seconds
The number of seconds to add
public
LocalDateTime
PlusMilliseconds​(long milliseconds)
Returns a new LocalDateTime representing the current value with the given number of milliseconds added.
Returns The current value plus the given number of milliseconds.
milliseconds
The number of milliseconds to add
public
LocalDateTime
PlusTicks​(long ticks)
Returns a new LocalDateTime representing the current value with the given number of ticks added.
Returns The current value plus the given number of ticks.
ticks
The number of ticks to add
public
LocalDateTime
PlusNanoseconds​(long nanoseconds)
Returns a new LocalDateTime representing the current value with the given number of nanoseconds added.
Returns The current value plus the given number of nanoseconds.
nanoseconds
The number of nanoseconds to add
public
LocalDateTime
Next​(IsoDayOfWeek targetDayOfWeek)
Returns the next <see cref="T:NodaTime.LocalDateTime" /> falling on the specified <see cref="T:NodaTime.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.
Returns The next <see cref="T:NodaTime.LocalDateTime" /> falling on the specified day of the week.
targetDayOfWeek
The ISO day of the week to return the next date of.
public
LocalDateTime
Previous​(IsoDayOfWeek targetDayOfWeek)
Returns the previous <see cref="T:NodaTime.LocalDateTime" /> falling on the specified <see cref="T:NodaTime.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.
Returns The previous <see cref="T:NodaTime.LocalDateTime" /> falling on the specified day of the week.
targetDayOfWeek
The ISO day of the week to return the previous date of.
public
OffsetDateTime
WithOffset​(Offset offset)
Returns an <see cref="T:NodaTime.OffsetDateTime" /> for this local date/time with the given offset.
Returns The result of this local date/time offset by the given amount.
offset
The offset to apply.
Remarks
This method is purely a convenient alternative to calling the <see cref="T:NodaTime.OffsetDateTime" /> constructor directly.
public
ZonedDateTime
InUtc​()
Returns the mapping of this local date/time within <see cref="P:NodaTime.DateTimeZone.Utc" /> .
Returns 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.
public
ZonedDateTime
InZoneStrictly​(DateTimeZone zone)
Returns the mapping of this local date/time within the given <see cref="T:NodaTime.DateTimeZone" /> ,
with "strict" rules applied such that an exception is thrown if either the mapping is
ambiguous or the time is skipped.
Returns The result of mapping this local date/time in the given time zone.
zone
The time zone in which to map this local date/time.
Remarks
See <see cref="M:NodaTime.LocalDateTime.InZoneLeniently(NodaTime.DateTimeZone)" /> and <see cref="M:NodaTime.LocalDateTime.InZone(NodaTime.DateTimeZone,NodaTime.TimeZones.ZoneLocalMappingResolver)" /> for alternative ways to map a local time to a
specific instant.
This is solely a convenience method for calling <see cref="M:NodaTime.DateTimeZone.AtStrictly(NodaTime.LocalDateTime)" /> .
public
ZonedDateTime
InZoneLeniently​(DateTimeZone zone)
Returns the mapping of this local date/time within the given <see cref="T:NodaTime.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".
Returns The result of mapping this local date/time in the given time zone.
zone
The time zone in which to map this local date/time.
Remarks
See <see cref="M:NodaTime.LocalDateTime.InZoneStrictly(NodaTime.DateTimeZone)" /> and <see cref="M:NodaTime.LocalDateTime.InZone(NodaTime.DateTimeZone,NodaTime.TimeZones.ZoneLocalMappingResolver)" /> for alternative ways to map a local time to a
specific instant.
This is solely a convenience method for calling <see cref="M:NodaTime.DateTimeZone.AtLeniently(NodaTime.LocalDateTime)" /> .
<para>Note: The behavior of this method was changed in version 2.0 to fit the most commonly seen real-world
usage pattern. Previous versions returned the later instance of ambiguous values, and returned the start of
the zone interval after the gap for skipped value. The previous functionality can still be used if desired,
by using <see cref="M:NodaTime.LocalDateTime.InZone(NodaTime.DateTimeZone,NodaTime.TimeZones.ZoneLocalMappingResolver)" /> and passing a resolver that combines the
<see cref="P:NodaTime.TimeZones.Resolvers.ReturnLater" /> and <see cref="P:NodaTime.TimeZones.Resolvers.ReturnStartOfIntervalAfter" /> resolvers.</para>
public
ZonedDateTime
InZone​(DateTimeZone zone,
ZoneLocalMappingResolver resolver)
Resolves this local date and time into a <see cref="T:NodaTime.ZonedDateTime" /> in the given time zone, following
the given <see cref="T:NodaTime.TimeZones.ZoneLocalMappingResolver" /> to handle ambiguity and skipped times.
Returns The result of resolving the mapping.
zone
The time zone to map this local date and time into
resolver
The resolver to apply to the mapping.
Remarks
See <see cref="M:NodaTime.LocalDateTime.InZoneStrictly(NodaTime.DateTimeZone)" /> and <see cref="M:NodaTime.LocalDateTime.InZoneLeniently(NodaTime.DateTimeZone)" /> for alternative ways to map a local time
to a specific instant.
This is a convenience method for calling <see cref="M:NodaTime.DateTimeZone.ResolveLocal(NodaTime.LocalDateTime,NodaTime.TimeZones.ZoneLocalMappingResolver)" /> .
public static
LocalDateTime
Max​(LocalDateTime x,
LocalDateTime y)
Returns the later date/time of the given two.
Returns The later date/time of <paramref name="x" /> or <paramref name="y" /> .
x
The first date/time to compare.
y
The second date/time to compare.
public static
LocalDateTime
Min​(LocalDateTime x,
LocalDateTime y)
Returns the earlier date/time of the given two.
Returns The earlier date/time of <paramref name="x" /> or <paramref name="y" /> .
x
The first date/time to compare.
y
The second date/time to compare.
public
string
ToString​()
Returns a <see cref="T:System.String" /> that represents this instance.
Returns The value of the current instance in the default format pattern ("G"), using the current thread's
culture to obtain a format provider.
public
string
ToString​(string patternText,
System.​IFormatProvider formatProvider)
Formats the value of the current instance using the specified pattern.
Returns A <see cref="T:System.String" /> containing the value of the current instance in the specified format.
patternText
The <see cref="T:System.String" /> specifying the pattern to use,
or null to use the default format pattern ("G").
formatProvider
The <see cref="T:System.IFormatProvider" /> to use when formatting the value,
or null to use the current thread's culture to obtain a format provider.
AddSchema​(System.​Xml.​Schema.​XmlSchemaSet xmlSchemaSet)
Adds the XML schema type describing the structure of the <see cref="T:NodaTime.LocalDateTime" /> XML serialization to the given <paramref name="xmlSchemaSet" /> .
the <paramref name="xmlSchemaSet" /> .
Returns The qualified name of the schema type that was added to the <paramref name="xmlSchemaSet" /> .
xmlSchemaSet
The XML schema set provided by <see cref="T:System.Xml.Serialization.XmlSchemaExporter" /> .
protected
void
Finalize​()
Inherited from object
protected
object
MemberwiseClone​()
Inherited from object