Skip to main content

Time

Use time helpers when a response should show the current time in a specific timezone.

Format current time​

Formats the current time using the v2 engine time layout.

Current timeAdvanced Script
const currentTime = time.format("America/New_York", "15:04");
async.messages.send(`New York time: ${currentTime}`);
Formatted dateAdvanced Script
const formattedDate = time.format("Europe/Berlin", "Monday January _2 15:04:05 2006");
async.messages.send(`Berlin: ${formattedDate}`);

API reference

time.format

time.format(timezone, layout)
Input
timezone
string

Timezone used for formatting.

layout
string

Runtime time layout string.

Output
string

Formatted current time.

Current runtime time​

Returns the current time, optionally in a timezone.

Current runtime timeAdvanced Script
const currentTime = time.now();
async.messages.send(`Current time: ${currentTime}`);

API reference

time.now

time.now(timezone?)
Input
timezoneoptional
string

IANA timezone name or UTC offset, depending on runtime support.

Output
string

Current time value formatted by the runtime.

Format duration​

Formats a duration in seconds as compact days, hours, minutes, and seconds.

Format durationAdvanced Script
const seconds = stats.watchtimeSeconds(sender.username);
async.messages.send(`Watchtime: ${time.duration(seconds)}`);

API reference

time.duration

time.duration(seconds)
Input
seconds
number

Duration in seconds.

Output
string

Formatted duration such as 1h 2m 3s.

Common layout tokens:

TokenMeaning
2006, 06Year
January, Jan, 01, 1Month
Monday, MonDay of week
2, _2, 02Day of month
15, 3, 03Hour
4, 04Minute
5, 05Second
PM, pmAM/PM marker