If epochNanoseconds is outside of this range, a RangeError will be thrown.Įxample usage: instant = new Temporal. This range covers approximately half a million years. The range of allowed values for this type is the same as the old-style JavaScript Date, 100 million (10 8) days before or after the Unix epoch. Otherwise, (), which accepts more kinds of input, is probably more convenient. Use this constructor directly if you know the precise number of nanoseconds already and have it in bigint form, for example from a database. epochNanoseconds (bigint): A number of nanoseconds.Ĭreates a new Temporal.Instant object that represents an exact time.ĮpochNanoseconds is the number of nanoseconds (10 −9 seconds) between the Unix epoch (midnight UTC on January 1, 1970) and the desired exact time. Constructor new Temporal.Instant( epochNanoseconds : bigint) : Temporal.Instant toPlainDate ( ) // => īugs in Date=> Temporal conversions can be caused by picking the wrong time zone when converting from Temporal.Instant to Temporal.ZonedDateTime.įor example, the example above constructs the Date using local-timezone parameters, so it uses the system time zone: ().īut if the Date had been initialized with a string like '', then getting the same date back in a Temporal.PlainDate would require using the 'UTC' time zone instead.įor discussion and code examples about picking the correct time zone, and also about Date Temporal interoperability in general, see Converting between Temporal types and legacy Date in the documentation cookbook. toTemporalInstant ( ) // => T18:30:00.123ZĪ Date that's been converted to a Temporal.Instant can be easily converted to a Temporal.ZonedDateTime object by providing a time zone.įrom there, calendar and clock properties like day or hour are available.Ĭonversions to narrower types like Temporal.PlainDate or Temporal.PlainTime are also provided. toISOString ( ) // => T18:30:00.123Z // Convert from `Date` to `Temporal.Instant` Convert from `Temporal.Instant` to `Date` (which uses millisecond precision) Temporal.Instant is the easiest way to interoperate between Temporal objects and code using Date.īecause Date and Temporal.Instant both use a time-since-epoch data model, conversions between them are zero-parameter method calls that are lossless (except sub-millisecond precision is truncated when converting to Date). Like Unix time, Temporal.Instant ignores leap seconds. Temporal.Instant stores a count of integer nanoseconds since the Unix epoch: midnight UTC on January 1, 1970.įor interoperability with Date and other APIs, Temporal.Instant also offers conversion properties and methods for seconds, milliseconds, or microseconds since epoch.Ī Temporal.Instant can also be created from an ISO 8601 / RFC 3339 string like 'T17:04:36.491865121-08:00' or 'T01:04Z'. epochNanoseconds // => 1577817000000000000n // `Temporal.Instant` lacks properties that depend on time zone or calendar To obtain local date/time units like year, month, day, or hour, a Temporal.Instant must be combined with a Temporal.TimeZone instance or a time zone string. No time zone or calendar information is present. Do try it and report bugs don't use it in production!Ī Temporal.Instant is a single point in time (called "exact time"), with a precision in nanoseconds.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |