Converting To and Using js-joda

node v10.15.3
version: 2.0.0
endpointsharetweet
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() // https://stackoverflow.com/a/32274316/85662 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()
Loading…

no comments

    sign in to comment