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.​Instant
Assembly: NodaTime
Implemented Interfaces
- System.​IEquatable`1
- System.​IComparable`1
- System.​IFormattable
- System.​IComparable
- System.​Xml.​Serialization.​IXmlSerializable
- System.​Numerics.​IAdditionOperators`3
- System.​Numerics.​ISubtractionOperators`3
- System.​Numerics.​ISubtractionOperators`3
- System.​Numerics.​IComparisonOperators`3 (Inherits: IEqualityOperators<​NodaTime.​Instant, NodaTime.​Instant, bool>)
- System.​Numerics.​IMinMaxValue`1
Represents an instant on the global timeline, with nanosecond resolution.
Remarks
<para>
An <see cref="T:NodaTime.Instant" /> has no concept of a particular time zone or calendar: it simply represents a point in
time that can be globally agreed-upon.
</para> <para>
Equality and ordering comparisons are defined in the natural way, with earlier points on the timeline
being considered "less than" later points.
</para> <para>The default value of this type is <see cref="P:NodaTime.NodaConstants.UnixEpoch" />, i.e. the instant
which can be represented as 1970-01-01T00:00:00Z in the ISO calendar.</para>
Properties
public static
Instant
MinValue
Represents the smallest possible <see cref="T:NodaTime.Instant" /> .
Remarks This value is equivalent to -9998-01-01T00:00:00Z
public static
Instant
MaxValue
Represents the largest possible <see cref="T:NodaTime.Instant" /> .
Remarks This value is equivalent to 9999-12-31T23:59:59.999999999Z
Methods
public
int
CompareTo​(Instant other)
Compares the current object with another object of the same type.
See the type documentation for a description of ordering semantics.
Returns A 32-bit signed integer that indicates the relative order of the objects being compared.
The return value has the following meanings:
<list type="table">
<listheader>
<term>Value</term>
<description>Meaning</description>
</listheader>
<item>
<term>< 0</term>
<description>This object is less than the <paramref name="other" /> parameter.</description>
</item>
<item>
<term>0</term>
<description>This object is equal to <paramref name="other" />.</description>
</item>
<item>
<term>> 0</term>
<description>This object is greater than <paramref name="other" />.</description>
</item>
</list>
other
An object to compare with this object.
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
Instant
PlusTicks​(long ticks)
Returns a new value of this instant with the given number of ticks added to it.
Returns The result of adding the given number of ticks to this instant.
ticks
The ticks to add to this instant to create the return value.
public
Instant
PlusNanoseconds​(long nanoseconds)
Returns a new value of this instant with the given number of nanoseconds added to it.
Returns The result of adding the given number of ticks to this instant.
nanoseconds
The nanoseconds to add to this instant to create the return value.
public static
Instant
Add​(Instant left,
Duration right)
Adds a duration to an instant. Friendly alternative to <c>operator+()</c> .
Returns A new <see cref="T:NodaTime.Instant" /> representing the sum of the given values.
left
The left hand side of the operator.
right
The right hand side of the operator.
public
Instant
Plus​(Duration duration)
Returns the result of adding a duration to this instant, for a fluent alternative to <c>operator+()</c> .
Returns A new <see cref="T:NodaTime.Instant" /> representing the result of the addition.
duration
The duration to add
public static
Duration
Subtract​(Instant left,
Instant right)
Subtracts one instant from another. Friendly alternative to <c>operator-()</c> .
Returns A new <see cref="T:NodaTime.Duration" /> representing the difference of the given values.
left
The left hand side of the operator.
right
The right hand side of the operator.
public
Duration
Minus​(Instant other)
Returns the result of subtracting another instant from this one, for a fluent alternative to <c>operator-()</c> .
Returns A new <see cref="T:NodaTime.Instant" /> representing the result of the subtraction.
other
The other instant to subtract
public static
Instant
Subtract​(Instant left,
Duration right)
Subtracts a duration from an instant. Friendly alternative to <c>operator-()</c> .
Returns A new <see cref="T:NodaTime.Instant" /> representing the difference of the given values.
left
The left hand side of the operator.
right
The right hand side of the operator.
public
Instant
Minus​(Duration duration)
Returns the result of subtracting a duration from this instant, for a fluent alternative to <c>operator-()</c> .
Returns A new <see cref="T:NodaTime.Instant" /> representing the result of the subtraction.
duration
The duration to subtract
public static
Instant
FromUtc​(int year,
int monthOfYear,
int dayOfMonth,
int hourOfDay,
int minuteOfHour)
Returns a new instant corresponding to the given UTC date and time in the ISO calendar.
In most cases applications should use <see cref="T:NodaTime.ZonedDateTime" /> to represent a date
and time, but this method is useful in some situations where an <see cref="T:NodaTime.Instant" /> is
required, such as time zone testing.
Returns An <see cref="T:NodaTime.Instant" /> value representing the given date and time in UTC and the ISO calendar.
year
The year. This is the "absolute year",
so a value of 0 means 1 BC, for example.
monthOfYear
The month of year.
dayOfMonth
The day of month.
hourOfDay
The hour.
minuteOfHour
The minute.
public static
Instant
FromUtc​(int year,
int monthOfYear,
int dayOfMonth,
int hourOfDay,
int minuteOfHour,
int secondOfMinute)
Returns a new instant corresponding to the given UTC date and
time in the ISO calendar. In most cases applications should
use <see cref="T:NodaTime.ZonedDateTime" />
to represent a date and time, but this method is useful in some
situations where an Instant is required, such as time zone testing.
Returns An <see cref="T:NodaTime.Instant" /> value representing the given date and time in UTC and the ISO calendar.
year
The year. This is the "absolute year",
so a value of 0 means 1 BC, for example.
monthOfYear
The month of year.
dayOfMonth
The day of month.
hourOfDay
The hour.
minuteOfHour
The minute.
secondOfMinute
The second.
public static
Instant
Max​(Instant x,
Instant y)
Returns the later instant of the given two.
Returns The later instant of <paramref name="x" /> or <paramref name="y" /> .
x
The first instant to compare.
y
The second instant to compare.
public static
Instant
Min​(Instant x,
Instant y)
Returns the earlier instant of the given two.
Returns The earlier instant of <paramref name="x" /> or <paramref name="y" /> .
x
The first instant to compare.
y
The second instant 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.
public
bool
Equals​(Instant other)
Indicates whether the value of this instant is equal to the value of the specified instant.
See the type documentation for a description of equality semantics.
Returns true if the value of this instant is equal to the value of the <paramref name="other" /> parameter;
otherwise, false.
other
The value to compare with this instance.
public
double
ToJulianDate​()
Returns the Julian Date of this instance - the number of days since
<see cref="P:NodaTime.NodaConstants.JulianEpoch" /> (noon on January 1st, 4713 BCE in the Julian calendar).
Returns The number of days (including fractional days) since the Julian Epoch.
ToDateTimeUtc​()
Constructs a <see cref="T:System.DateTime" /> from this Instant which has a <see cref="P:System.DateTime.Kind" />
of <see cref="F:System.DateTimeKind.Utc" /> and represents the same instant of time as this value.
Returns A <see cref="T:System.DateTime" /> representing the same instant in time as this value, with a kind of "universal".
Remarks
<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>
ToDateTimeOffset​()
Constructs a <see cref="T:System.DateTimeOffset" /> from this Instant which has an offset of zero.
Returns A <see cref="T:System.DateTimeOffset" /> representing the same instant in time as this value.
Remarks
<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>
public static
Instant
FromDateTimeOffset​(System.​DateTimeOffset dateTimeOffset)
Converts a <see cref="T:System.DateTimeOffset" /> into a new Instant representing the same instant in time. Note that
the offset information is not preserved in the returned Instant.
Returns An <see cref="T:NodaTime.Instant" /> value representing the same instant in time as the given <see cref="T:System.DateTimeOffset" /> .
dateTimeOffset
Date and time value with an offset.
public static
Instant
FromJulianDate​(double julianDate)
Converts a Julian Date representing the given number of days
since <see cref="P:NodaTime.NodaConstants.JulianEpoch" /> (noon on January 1st, 4713 BCE in the Julian calendar)
into an <see cref="T:NodaTime.Instant" /> .
Returns An <see cref="T:NodaTime.Instant" /> value which is <paramref name="julianDate" /> days after the Julian Epoch.
julianDate
The number of days since the Julian Epoch to convert into an <see cref="T:NodaTime.Instant" /> .
public static
Instant
FromDateTimeUtc​(System.​DateTime dateTime)
Converts a <see cref="T:System.DateTime" /> into a new Instant representing the same instant in time.
Returns An <see cref="T:NodaTime.Instant" /> value representing the same instant in time as the given universal <see cref="T:System.DateTime" /> .
dateTime
Date and time value which must have a <see cref="P:System.DateTime.Kind" /> of <see cref="F:System.DateTimeKind.Utc" />
public static
Instant
FromUnixTimeSeconds​(long seconds)
Initializes a new instance of the <see cref="T:NodaTime.Instant" /> struct based
on a number of seconds since the Unix epoch of (ISO) January 1st 1970, midnight, UTC.
Returns An <see cref="T:NodaTime.Instant" /> at exactly the given number of seconds since the Unix epoch.
seconds
Number of seconds since the Unix epoch. May be negative (for instants before the epoch).
public static
Instant
FromUnixTimeMilliseconds​(long milliseconds)
Initializes a new instance of the <see cref="T:NodaTime.Instant" /> struct based
on a number of milliseconds since the Unix epoch of (ISO) January 1st 1970, midnight, UTC.
Returns An <see cref="T:NodaTime.Instant" /> at exactly the given number of milliseconds since the Unix epoch.
milliseconds
Number of milliseconds since the Unix epoch. May be negative (for instants before the epoch).
public static
Instant
FromUnixTimeTicks​(long ticks)
Initializes a new instance of the <see cref="T:NodaTime.Instant" /> struct based
on a number of ticks since the Unix epoch of (ISO) January 1st 1970, midnight, UTC.
Returns An <see cref="T:NodaTime.Instant" /> at exactly the given number of ticks since the Unix epoch.
ticks
Number of ticks since the Unix epoch. May be negative (for instants before the epoch).
public
long
ToUnixTimeSeconds​()
Gets the number of seconds since the Unix epoch. Negative values represent instants before the Unix epoch.
Remarks
If the number of nanoseconds in this instant is not an exact number of seconds, the value is truncated towards the start of time.
public
System.​ValueTuple<​long, int>
ToUnixTimeSecondsAndNanoseconds​()
Gets the number of seconds since the Unix epoch, along with remaining nanoseconds.
Negative values for seconds represent instants before the Unix epoch.
Remarks
<para>
If the number of nanoseconds in this instant is not an exact number of seconds
the seconds part of the returned value is truncated towards the start of time, ensuring that
the nanoseconds part is always non-negative. The seconds part of the returned value is always
the same as would be returned by <see cref="M:NodaTime.Instant.ToUnixTimeSeconds" />.
</para> <para>
The inverse of this operation is to first call <see cref="M:NodaTime.Instant.FromUnixTimeSeconds(System.Int64)" /> and then
call <see cref="M:NodaTime.Instant.PlusNanoseconds(System.Int64)" /> on the returned <see cref="T:NodaTime.Instant" />.
</para>
public
long
ToUnixTimeMilliseconds​()
Gets the number of milliseconds since the Unix epoch. Negative values represent instants before the Unix epoch.
Remarks
If the number of nanoseconds in this instant is not an exact number of milliseconds, the value is truncated towards the start of time.
public
long
ToUnixTimeTicks​()
Gets the number of ticks since the Unix epoch. Negative values represent instants before the Unix epoch.
Returns The number of ticks since the Unix epoch.
Remarks
A tick is equal to 100 nanoseconds. There are 10,000 ticks in a millisecond. If the number of nanoseconds
in this instant is not an exact number of ticks, the value is truncated towards the start of time.
public
ZonedDateTime
InUtc​()
Returns the <see cref="T:NodaTime.ZonedDateTime" /> representing the same point in time as this instant, in the UTC time
zone and ISO-8601 calendar. This is a shortcut for calling <see cref="M:NodaTime.Instant.InZone(NodaTime.DateTimeZone)" /> with an
argument of <see cref="P:NodaTime.DateTimeZone.Utc" /> .
Returns A <see cref="T:NodaTime.ZonedDateTime" /> for the same instant, in the UTC time zone
and the ISO-8601 calendar
public
ZonedDateTime
InZone​(DateTimeZone zone)
Returns the <see cref="T:NodaTime.ZonedDateTime" /> representing the same point in time as this instant, in the
specified time zone and ISO-8601 calendar.
Returns A <see cref="T:NodaTime.ZonedDateTime" /> for the same instant, in the given time zone
and the ISO-8601 calendar
zone
The time zone in which to represent this instant.
public
ZonedDateTime
InZone​(DateTimeZone zone,
CalendarSystem calendar)
Returns the <see cref="T:NodaTime.ZonedDateTime" /> representing the same point in time as this instant, in the
specified time zone and calendar system.
Returns A <see cref="T:NodaTime.ZonedDateTime" /> for the same instant, in the given time zone
and calendar
zone
The time zone in which to represent this instant.
calendar
The calendar system in which to represent this instant.
public
OffsetDateTime
WithOffset​(Offset offset)
Returns the <see cref="T:NodaTime.OffsetDateTime" /> representing the same point in time as this instant, with
the specified UTC offset in the ISO calendar system.
Returns An <see cref="T:NodaTime.OffsetDateTime" /> for the same instant, with the given offset
in the ISO calendar system
offset
The offset from UTC with which to represent this instant.
public
OffsetDateTime
WithOffset​(Offset offset,
CalendarSystem calendar)
Returns the <see cref="T:NodaTime.OffsetDateTime" /> representing the same point in time as this instant, with
the specified UTC offset and calendar system.
Returns An <see cref="T:NodaTime.OffsetDateTime" /> for the same instant, with the given offset
and calendar
offset
The offset from UTC with which to represent this instant.
calendar
The calendar system in which to represent this instant.
AddSchema​(System.​Xml.​Schema.​XmlSchemaSet xmlSchemaSet)
Adds the XML schema type describing the structure of the <see cref="T:NodaTime.Instant" /> XML serialization to the given <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