Converting To and Using js-joda

node v10.16.3
version: 2.0.0
The native JavaScript Date library is very, well, _lightweight_, so libraries such as js-joda can help. Once a native date is converted to a js-joda one, with a little (unnecessary?!) help:
const { LocalDate } = require("js-joda") const nativeDate = new Date() // const localDate = LocalDate.parse(new Date().toISOString().split("T")[0])
... you can start to take advantage of its powerful features:
const { TemporalAdjusters } = require("js-joda") localDate.with(TemporalAdjusters.firstDayOfMonth())
This can be serialised back to a standard JavaScript date object as needed:
const { convert } = require("js-joda") convert(localDate).toDate()

no comments

    sign in to comment