The DateDuration
class represents a duration of time specified in milliseconds. It provides methods to calculate and retrieve information about the duration.
pnpm add @jmondi/date-duration
import { DateDuration } from "https://deno.land/x/date_duration";
The class is based on the ms package.
const duration = new DateDuration("2d");
Access the properties and methods of the DateDuration
instance:
console.log(duration.endDate); // Get the end date as a JavaScript Date object
console.log(duration.endTimeMs); // Get the end time in milliseconds
console.log(duration.endTimeSeconds); // Get the end time in seconds (rounded up)
console.log(duration.seconds); // Get the duration in seconds (rounded up)
You can also use the static method getDateEnd
to get the end date directly without creating an instance:
const endDate = DateDuration.getDateEnd("1w");
console.log(endDate); // Get the end date as a JavaScript Date object