Time
Use time helpers when a response should show the current time in a specific timezone.
- Engine v2
- Engine v1
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
timezonestringTimezone used for formatting.
layoutstringRuntime time layout string.
Output
stringFormatted 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
timezoneoptionalstringIANA timezone name or UTC offset, depending on runtime support.
Output
stringCurrent 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
secondsnumberDuration in seconds.
Output
stringFormatted duration such as 1h 2m 3s.
Common layout tokens:
| Token | Meaning |
|---|---|
2006, 06 | Year |
January, Jan, 01, 1 | Month |
Monday, Mon | Day of week |
2, _2, 02 | Day of month |
15, 3, 03 | Hour |
4, 04 | Minute |
5, 05 | Second |
PM, pm | AM/PM marker |
The current time in New York is {{time "America/New_York"}}.
The current time in New York is {{timeFmt "America/New_York" "03:04 pm"}}.
The current time in New York is {{timeFmt "America/New_York" "15:04:05"}}.