Skip to main content

Class: Timestamp

@sapphire/timestamp.Timestamp

Timestamp class, parses the pattern once, displays the desired Date or UNIX timestamp with the selected pattern.

Constructors

constructor

new Timestamp(pattern)

Starts a new Timestamp and parses the pattern.

Since

1.0.0

Parameters

NameTypeDescription
patternstringThe pattern to parse

Defined in

lib/Timestamp.ts:142

Properties

pattern

pattern: string

The raw pattern

Since

1.0.0

Defined in

lib/Timestamp.ts:130


template

Private template: TimestampTemplateEntry[]

Since

1.0.0

Defined in

lib/Timestamp.ts:135

Methods

display

display(time?): string

Display the current date with the current pattern.

Since

1.0.0

Parameters

NameTypeDescription
timeTimeResolvableThe time to display

Returns

string

Defined in

lib/Timestamp.ts:152


displayUTC

displayUTC(time?): string

Display the current date utc with the current pattern.

Since

1.0.0

Parameters

NameTypeDescription
time?TimeResolvableThe time to display in utc

Returns

string

Defined in

lib/Timestamp.ts:161


edit

edit(pattern): Timestamp

Edits the current pattern.

Since

1.0.0

Chainable

Parameters

NameTypeDescription
patternstringThe new pattern for this instance

Returns

Timestamp

Defined in

lib/Timestamp.ts:171


toString

toString(): string

Defines the toString behavior of Timestamp.

Returns

string

Defined in

lib/Timestamp.ts:180


display

Private Static display(template, time): string

Display the current date with the current pattern.

Since

1.0.0

Parameters

NameTypeDescription
templateTimestampTemplateEntry[]The pattern to parse
timestring | number | DateThe time to display

Returns

string

Defined in

lib/Timestamp.ts:220


displayArbitrary

Static displayArbitrary(pattern, time?): string

Display the current date with the current pattern.

Since

1.0.0

Parameters

NameTypeDescription
patternstringThe pattern to parse
timeTimeResolvableThe time to display

Returns

string

Defined in

lib/Timestamp.ts:190


displayUTCArbitrary

Static displayUTCArbitrary(pattern, time?): string

Display the current date utc with the current pattern.

Since

1.0.0

Parameters

NameTypeDescription
patternstringThe pattern to parse
timeTimeResolvableThe time to display

Returns

string

Defined in

lib/Timestamp.ts:200


parse

Private Static parse(pattern): TimestampTemplateEntry[]

Parses the pattern.

Since

1.0.0

Parameters

NameTypeDescription
patternstringThe pattern to parse

Returns

TimestampTemplateEntry[]

Defined in

lib/Timestamp.ts:232


resolveDate

Private Static resolveDate(time): Date

Resolves a date.

Since

1.0.0

Parameters

NameTypeDescription
timeTimeResolvableThe time to parse

Returns

Date

Defined in

lib/Timestamp.ts:261


utc

Static utc(time?): Date

Creates a UTC Date object to work with.

Since

1.0.0

Parameters

NameTypeDescription
timestring | number | DateThe date to convert to utc

Returns

Date

Defined in

lib/Timestamp.ts:209