Clone and edit this document
Runkit
Runkit
home page
user forum
new notebook
clone notebook
download notebook
support & documentation
log in
sign up
new notebook
help & feedback
clone this notebook
download this notebook
Sign In
Sign Up
Converting To and Using js-joda
node v10.24.1
version:
2.0.0
endpoint
share
tweet
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