Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/durationjs/src/duration.ts>Duration

Get the formated time duration
Latest
class Duration
implements DurationObjWithRaw
import { Duration } from "https://deno.land/x/durationjs@v4.1.1/src/duration.ts";

A simple JavaScript class used to parse time durations

Constructors

new
Duration(timestamp?: number)

Parse milliseconds into separate units of time.

Properties

readonly
array: KeyValue[]

An array of time units and their values.

d: number
readonly
days

Alias for this.d

h: number
readonly
hours

Alias for this.h

readonly
json: DurationObj

Data in the class mapped as a JavaScript Object.

m: number
readonly
microseconds

Alias for this.us

readonly
milliseconds

Alias for this.ms

readonly
minutes

Alias for this.m

ms: number
readonly
nanoseconds

Alias for this.ns

ns: number
raw: number
s: number
readonly
seconds

Alias for this.s

us: number
readonly
µs: number

Alias for this.us

Methods

addDays(n: number): Duration

Add more days to the duration.

addHours(n: number): Duration

Add more hours to the duration.

Add more microseconds to the duration.

Add more milliseconds to the duration.

addMinutes(n: number): Duration

Add more minutes to the duration.

Add more nanoseconds to the duration.

addSeconds(n: number): Duration

Add more seconds to the duration.

asDays(): number

Get duration as days.

asHours(): number

Get duration as hours.

asMicroseconds(): number

Get duration as microseconds.

asMilliseconds(): number

Get duration as milliseconds.

asMinutes(): number

Get duration as minutes.

asNanoseconds(): number

Get duration as nanoseconds.

asSeconds(): number

Get duration as seconds.

Clone current duration (run Duration#reload before this if you manually tweaked the properties).

Get a simple formatted duration in the form dd:hh:mm:ss:ms (Deprecated. Use Duration#toString())

Update data to match any modification to values.

setDays(n: number): Duration

Set days of the duration.

setHours(n: number): Duration

Set hours of the duration.

Set microseconds of the duration.

Set milliseconds of the duration.

setMinutes(n: number): Duration

Set minutes of the duration.

Set nanoseconds of the duration.

setSeconds(n: number): Duration

Set seconds of the duration.

toDescriptiveString(values?: string[] | null): string

Get a formatted, human-readable string of the duration.

Convert the Duration into a plain object.

toShortString(values?: string[] | null): string

Get a formatted, human-readable string of the duration.

toString(): string

Get a simple formatted duration in the form dd:hh:mm:ss:ms

toTimeString(fromT?: keyof DurationObj, toT?: keyof DurationObj): string

Get a duration formatted using colons (:).

toWordString(values?: string[] | null): string

Get a human-readable string of the duration in words.

valueOf(): number

Just the valueOf method.

Static Methods

between(duration1:
| string
| number
| Date
, duration2:
| string
| number
| Date
| undefined
| null
): Duration

Get the duration between two timestamps or two other durations.

fromString(str: string, doNotParse?): Duration

Reads a given string and parses a duration from it.

Get the duration till next midnight in milliseconds.

Read duration data from a string.

since(when: number | Date): Duration

Get duration since a moment in time.