How to subtract dates in Node.js

Need to subtract dates in Node.js? No problem, let’s use Java for that. After installing GraalVM using SDKMAN: $ sdk install java 20.0.1-graal as well as installing GraalVM’s Node.js runtime using gu1: $ gu install nodejs we can now perform some black magic: // index.js // "Import" LocalDate & ChronoUnit from ☕️ const LocalDate = Java.type("java.time.LocalDate"); const ChronoUnit = Java.type("java.time.temporal.ChronoUnit"); const firstDate = LocalDate.of(2023, 7, 20); const secondDate = LocalDate.of(2023, 8, 4); console....

July 20, 2023 · 1 min · Abdelrahman Abdelhafez