Developer Reference

Discord Timestamp Code Snippets for JS, Python, Discord.js, and Go

Zero-dependency production snippets for formatting Discord timestamp tags, Webhook ISO 8601 footers, and BigInt Snowflake ID decoders across major bot languages.

Test Epochs in Unix Converter Explore All Tools
Discord Snowflake 42-bit timestamp and Unix epoch engineering diagram for JavaScript and Python bots
Generate dynamic <t:UNIX:FORMAT> tags and decode 64-bit Snowflake timestamps cleanly in JavaScript, Python, and discord.js.

What Developers Need to Know About Discord Timestamp Code

Building a reliable Discord timestamp in bot code or webhook automations comes down to three strict engineering rules: message-body tags (<t:UNIX:FLAG>) require 10-digit integer Unix seconds (never 13-digit milliseconds and never float decimals), embed footer clocks (embed.timestamp) require strict ISO 8601 UTC strings, and Discord Snowflake IDs must be parsed as 64-bit integers (BigInt in JavaScript) to avoid IEEE-754 precision loss.

Every snippet below is zero-bloat, tested against Discord's live parser, and ready to drop into Discord.js v14, Discord.py 2.x, vanilla TypeScript, Python 3, Go, or raw Webhook HTTP requests.

How to Format a Discord Timestamp Safely in 4 Steps

1. Always Normalize Dates to Integer UTC Unix Seconds

Convert your date object in UTC first, then floor to whole seconds (Math.floor(ms / 1000) in JS, int(dt.timestamp()) in Python, t.Unix() in Go). Never rely on a host container's local timezone for wall-clock math.

2. Choose an Explicit Case-Sensitive Format Flag

Pass one of Discord's nine official flags (t, T, d, D, f, F, s, S, or uppercase R) rather than assuming defaults, and validate that relative cooldowns always use uppercase R.

3. Keep Dynamic Tags Inside Supported Embed Fields

Place <t:UNIX:FLAG> tags inside content, embeds[].description, or embeds[].fields[].value. Never place Markdown timestamps inside embed.title, fields[].name, or footer.text.

4. Use Strict ISO 8601 UTC Strings for embed.timestamp

Pass a UTC ISO string ending in Z (2026-11-25T12:00:00.000Z) to embed.timestamp and convert hex colors to base-10 integers so Discord never rejects your webhook with HTTP 400 Bad Request.

Core Code Features Covered Across Major Bot Languages

Vanilla JavaScript and TypeScript Helper (Zero Dependencies)

Always divide JavaScript milliseconds by 1000 and apply Math.floor() before constructing a Discord timestamp string:

/**
 * Format any Date, Unix ms number, or ISO string as a Discord timestamp tag.
 * Valid styles: "t" | "T" | "d" | "D" | "f" | "F" | "s" | "S" | "R"
 */
export function discordTimestamp(date = new Date(), style = "F") {
  const unixSeconds = Math.floor(new Date(date).getTime() / 1000);
  return "<t:" + unixSeconds + ":" + style + ">";
}

// Examples:
const cooldownTag = discordTimestamp(Date.now() + 60_000, "R");
const launchTag = discordTimestamp("2026-12-31T23:59:00Z", "F");

Discord.js v14 Official Built-In Formatter

Discord.js v14 exports typed helpers from @discordjs/formatters so you avoid manual integer math and typos when assembling a Discord timestamp inside slash commands and embeds:

import { time, TimestampStyles, EmbedBuilder } from "discord.js";

const launchDate = new Date("2026-12-01T18:00:00Z");
const fullTag = time(launchDate, TimestampStyles.LongDateTime);
const relTag = time(launchDate, TimestampStyles.RelativeTime);

const embed = new EmbedBuilder()
  .setTitle("Season Launch")
  .setDescription("Starts " + fullTag + " (" + relTag + ")")
  .setColor(0x5865f2)
  .setTimestamp(launchDate); // Serialized to ISO 8601 UTC automatically

Python 3 and Discord.py 2.x (Timezone-Aware UTC)

Always pass tzinfo=timezone.utc when building Python datetime objects so deploying from a local workstation to a cloud Linux container never shifts your Discord timestamp output:

from datetime import datetime, timezone
import discord

dt = datetime(2026, 12, 1, 18, 0, tzinfo=timezone.utc)

# Pure Python (zero external deps, strict integer seconds):
unix_sec = int(dt.timestamp())
tag_combo = "<t:%d:F> (<t:%d:R>)" % (unix_sec, unix_sec)

# Discord.py 2.x official helper:
tag_dpy = discord.utils.format_dt(dt, "F") + " (" + discord.utils.format_dt(dt, "R") + ")"

# Strict Webhook / Embed footer ISO 8601 UTC string:
iso_footer = dt.isoformat().replace("+00:00", "Z")

Decoding Discord Snowflake IDs in JavaScript (BigInt) and Python

Discord's custom Snowflake epoch is 1420070400000 (2015-01-01T00:00:00.000Z). Shift right by 22 bits to extract exact creation milliseconds and divide by 1000 for a Discord timestamp:

// JavaScript: ALWAYS pass Snowflake ID as a string to preserve 64-bit precision!
const DISCORD_EPOCH = 1420070400000n;
export function snowflakeToUnixSeconds(idStr) {
  const unixMs = Number((BigInt(idStr) >> 22n) + DISCORD_EPOCH);
  return Math.floor(unixMs / 1000);
}
# Python supports arbitrary-precision integers natively:
DISCORD_EPOCH_MS = 1420070400000

def snowflake_to_datetime(snowflake_id: str | int) -> datetime:
    unix_ms = (int(snowflake_id) >> 22) + DISCORD_EPOCH_MS
    return datetime.fromtimestamp(unix_ms / 1000, tz=timezone.utc)

Go (Golang) Bot Helper

Go's time.Time.Unix() returns a 64-bit integer in seconds natively, making Discord timestamp formatting completely concise:

package main

import (
    "fmt"
    "time"
)

func DiscordTimestamp(t time.Time, style string) string {
    return fmt.Sprintf("<t:%d:%s>", t.Unix(), style)
}

Developer Use Cases for Programmatic Discord Timestamps

Command Cooldowns and Rate-Limit Notices

Return "Slow down! You can run this command again <t:UNIX:R>." using now + cooldownSeconds so users watch their own lockout tick to zero live.

Automated CI/CD, GitHub Actions, and Release Webhooks

Format build completion timestamps in both embed.timestamp (ISO 8601) and embed.description (<t:UNIX:F> (<t:UNIX:R>)) so distributed engineering teams read deploys in local time.

Moderation Logs and Account-Age Filters

Extract exact user creation dates from incoming joiner Snowflake IDs using BigInt bit-shifting and flag accounts newer than 24 hours with clickable <t:UNIX:R> badges in #mod-logs.

Scheduled Reminders and Cron-Driven Server Events

Store a single integer UTC Unix second per scheduled event in PostgreSQL, SQLite, or Cloudflare D1, then render it dynamically in any of the 9 official Discord Timestamp Formats at send time.

Who Uses These Discord Timestamp Code Snippets?

Discord.js and Discord.py Bot Authors

Bot maintainers building economy cooldowns, giveaway engines, moderation suites, and raid schedulers copy these tested helpers to avoid millisecond and naive-datetime bugs.

DevOps and Webhook Integrators

Engineers wiring GitHub Actions, Stripe alerts, Sentry errors, and uptime monitors into Discord webhooks pair our code with the Embed Timestamp JSON validator.

Full-Stack Web and No-Code Automation Builders

Developers running Zapier, Make, n8n, or Cloudflare Workers scripts verify exact integer second math rapidly before pushing to production.

Why Choose This Developer Reference?

Short forum snippets often miss Math.floor(), omit tzinfo=timezone.utc in Python, ignore BigInt precision loss on 18-digit Snowflake IDs, or skip Discord's compact :s and :S styles. Every helper on this page handles those real production traps cleanly, runs with zero heavy dependencies, and links straight to browser-local verification tools so you can test every epoch and webhook payload before shipping.

Common Production Bugs to Catch Before Deploying

  • 13-digit milliseconds in <t:...>: Always divide JS Date.now() by 1000 and floor; otherwise Discord prints year +58865. Test numbers in our Discord Unix Converter.
  • Float decimals from Python time.time(): Wrap in int(...) so no decimal point ever enters the tag.
  • Unquoted Snowflakes in JSON payloads: Always deserialize Discord IDs as strings before passing them to BigInt(id) (verify live on our Snowflake ID Decoder).
  • Broken live output in staging: Drop any failing bot message straight into our Timestamp Syntax Fixer for instant diagnostics.
Independently Verified Technical Guide · Updated Nov 2026

Tested against Discord's official Unix timestamp specification (<t:UNIX:FORMAT>) and IANA tzdb across Desktop, iOS, and Android. Independent utility, not affiliated with Discord Inc.

FAQ

Frequently Asked Questions

How do I generate a Discord timestamp in vanilla JavaScript without libraries?

Divide Date.now() or date.getTime() by 1000 and apply Math.floor() to obtain a clean 10-digit integer, then assemble '<t:' + unixSeconds + ':R>'. Never pass raw 13-digit milliseconds into a Discord timestamp tag.

Does Discord.js v14 include an official built-in Discord timestamp helper?

Yes. Import time and TimestampStyles from discord.js (backed by @discordjs/formatters). Calling time(new Date(), TimestampStyles.RelativeTime) converts milliseconds to integer seconds automatically and prevents typos.

How do I format a Discord timestamp in Python 3 and Discord.py 2.x?

In standard Python, create a UTC-aware datetime object, convert with int(dt.timestamp()), and format '<t:%d:%s>' % (unix_sec, 'R'). In Discord.py 2.x, call discord.utils.format_dt(dt, style='R') directly.

Why must Python developers avoid naive datetime objects when computing a Discord timestamp?

Calling .timestamp() on a naive Python datetime (without tzinfo=timezone.utc) interprets the clock in your server host's local timezone. Moving a bot from a US laptop to a UTC cloud container silently shifts every Discord timestamp by several hours.

Why must Discord Snowflake IDs always use BigInt in JavaScript?

JavaScript's IEEE-754 Number loses integer precision above 9007199254740991 (2^53 - 1, 16 digits), which silently rounds the final digits of 18-digit and 19-digit Discord Snowflake IDs. Always pass IDs as strings and shift with BigInt.

Why did my bot's Discord timestamp fail when I passed time.time() directly in Python?

Python time.time() returns a floating-point number with decimals like 1795579200.4182. Discord rejects decimal points inside <t:...>. Wrap time.time() in int(time.time()) so the Unix value is strictly an integer.

How do I format a Discord embed footer timestamp in Discord.js or Discord.py?

Embed footers require ISO 8601 UTC strings rather than <t:...> tags. Use .setTimestamp(date) in Discord.js EmbedBuilder, pass timestamp=datetime.now(timezone.utc) in discord.py Embed, or send dt.isoformat().replace('+00:00', 'Z') in raw Webhook JSON.

Do Discord.js and Discord.py support the newer :s and :S Discord timestamp formats?

Yes. Even if an older library release has not added enum names for 's' and 'S' yet, passing the single-character string 's' or 'S' into format_dt(dt, 's') or assembling '<t:' + sec + ':s>' works natively in every Discord client.

How do I generate a Discord timestamp cooldown timer 60 seconds in the future?

Add 60 to the current 10-digit Unix second: Math.floor(Date.now() / 1000) + 60 in JavaScript, int(time.time()) + 60 in Python, or time.Now().Add(time.Minute).Unix() in Go, then format with uppercase :R.

How do I convert a Discord Snowflake ID back into a Discord timestamp in code?

Right-shift the 64-bit Snowflake by 22 bits, add Discord's custom epoch 1420070400000 milliseconds, and divide by 1000 to get 10-digit Unix seconds suitable for <t:UNIX:F> or <t:UNIX:R>.

How do I create a Discord timestamp in Go (Golang) or PHP?

In Go, call t.Unix() which already returns 64-bit integer seconds and format with fmt.Sprintf('<t:%d:%s>', t.Unix(), style). In PHP, time() already returns integer Unix seconds directly.

Where can I test my bot's generated Webhook JSON or Unix epochs before deploying?

Paste raw Unix numbers into our Unix Converter, test Webhook JSON in our Embed Timestamp JSON builder, or decode sample IDs in our Snowflake Decoder—all 100% locally in your browser.

Ready

Ready to Test Your Discord Timestamp Output Live?

Verify any generated 10-digit epoch, ISO 8601 webhook JSON, or 18-digit Snowflake bit-shift instantly in our client-side developer converters.

Copied to clipboard