TimeCord — Timestamps for Discord
TimeCord is a Node.js module that allows you to easily create timestamps!
Installation
npm install timecord
yarn add timecord
Basic usage
const { DiscordTimestamp } = require('timecord');
const timestamp = new DiscordTimestamp();
console.log(timestamp.format());
Example
const { Client } = require('discord.js');
const client = new Client(...);
const { DiscordTimestamp } = require('timecord');
client.on('interactionCreate', (interaction) => {
if (interaction.isChatInputCommand() && interaction.commandName === 'test-timestamp') {
const createdDate = new DiscordTimestamp(interaction.createdAt).format();
return interaction.reply({
content: `Interaction created date: ${createdDate}`
});
}
});
Advanced example
const { DiscordTimestamp, StyleType, TimeUnits } = require('timecord');
const timestamp = new DiscordTimestamp(new Date(), StyleType.RelativeTime);
console.log(`You will be able to use this command again ${timestamp.addTime(2, TimeUnits.Hours).format()}.`);
Methods
Types
| TimestampResolvable | Date | number | string |
| TimestampStyle | "t" | "T" | "d" | "D" | "f" | "F" | "R" |
| TimestampResult | `<t:${number}:${StyleType[number]}>` |
| StyleResolvable | StyleType | keyof typeof StyleType |
| TimeUnitResolvable | TimeUnits | keyof typeof TimeUnits |
Enums
| TimeUnits | Miliseconds
Seconds
Minutes
Hours
Days | 1
1000
60000
3.6e6
8.64e7 | This will be multiplied by the number passed by parameters in a function.
<Number> * <Value> |
| StyleType | ShortTime
LongTime
ShortDate
LongDate
ShortDateAndTime
LongDateAndTime
RelativeTime | 't'
'T'
'd'
'D'
'f'
'F'
'R' | 16:20
16:20:30
20/04/2021
20 April 2021
20 April 2021 16:20
Tuesday, 20 April 2021 16:20
2 months ago |