Function
Static Public Summary | ||
public |
convert(temporal: LocalDate | LocalDateTime | ZonedDateTime, zone: ZoneId): ToNativeJsConverter converts a LocalDate, LocalDateTime or ZonedDateTime to a native Javascript Date. |
|
public |
nativeJs(date: Date | moment, zone: ZoneId): ZonedDateTime Creates ZonedDateTime from a javascript Date or a moment instance. |
Static Public
public convert(temporal: LocalDate | LocalDateTime | ZonedDateTime, zone: ZoneId): ToNativeJsConverter source
import {convert} from '@js-joda/root/packages/core/src/convert.js'
converts a LocalDate, LocalDateTime or ZonedDateTime to a native Javascript Date.
In a first step the temporal is converted to an Instant by adding implicit values.
A LocalDate is implicit set to a LocalDateTime at start of day. A LocalDateTime is implicit set to a ZonedDateTime with the passed zone or if null, with the system default time zone. A ZonedDateTime is converted to an Instant, if a zone is specified the zonedDateTime is adjusted to this zone, keeping the same Instant.
In a second step the instant is converted to a native Javascript Date
default zone for LocalDate and LocalDateTime is ZoneId.systemDefault().
Params:
Name | Type | Attribute | Description |
temporal | LocalDate | LocalDateTime | ZonedDateTime |
|
a joda temporal instance |
zone | ZoneId |
|
the zone of the temporal |
Return:
ToNativeJsConverter |
Example:
convert(localDate).toDate() // returns a javascript Date
convert(localDate).toEpochMilli() // returns the epochMillis
public nativeJs(date: Date | moment, zone: ZoneId): ZonedDateTime source
import {nativeJs} from '@js-joda/root/packages/core/src/nativeJs.js'
Creates ZonedDateTime from a javascript Date or a moment instance.
Params:
Name | Type | Attribute | Description |
date | Date | moment |
|
a javascript Date or a moment instance |
zone | ZoneId |
|
the zone of the returned ZonedDateTime, defaults to ZoneId.systemDefault() |