Current epoch — epochtime.tools · A precision instrument for time
Try:

Discord and X use different epochs

A snowflake keeps its timestamp in the top 42 bits (41 in X's original layout) as milliseconds since a chosen start date. Shift the ID right by 22 bits, add the epoch, and you have Unix milliseconds. The catch is that each service picks its own epoch, so the same number decodes to different dates. The decoder shows both readings and puts the more likely one first.

ServiceEpochEpoch in Unix ms
Discord2015-01-01T00:00:00.000Z1420070400000
X (Twitter)2010-11-04T01:42:54.657Z1288834974657

Discord snowflake layout

BitsFieldHow to read it
63–22Timestamp: ms since the Discord epoch(id >> 22) + 1420070400000
21–17Internal worker ID(id & 0x3E0000) >> 17
16–12Internal process ID(id & 0x1F000) >> 12
11–0Incrementid & 0xFFF

Worked example (from Discord's documentation)

  1. Take the ID 175928847299117063.
  2. Shift right by 22 bits: 41944705796 milliseconds since the Discord epoch.
  3. Add 1420070400000: 1462015105796, which is 2016-04-30T11:18:25.796Z.
  4. The remaining bits give worker 1, process 0 and increment 7.

For X, the same steps with the X epoch turn post ID 1585841080431321088 into 378093977077 + 1288834974657 = 2022-10-28T03:49:11.734Z.

Code

Snowflakes are larger than 253, so JavaScript numbers lose the last digits. Use BigInt and keep IDs as strings, as both Discord and X advise.

JavaScript

const DISCORD_EPOCH = 1420070400000n;
const X_EPOCH = 1288834974657n;
const snowflakeDate = (id, epoch) => new Date(Number((BigInt(id) >> 22n) + epoch));

snowflakeDate('175928847299117063', DISCORD_EPOCH).toISOString();
// '2016-04-30T11:18:25.796Z'

Python

from datetime import datetime, timezone
DISCORD_EPOCH = 1420070400000

def snowflake_date(snowflake: int, epoch: int = DISCORD_EPOCH) -> datetime:
    return datetime.fromtimestamp(((snowflake >> 22) + epoch) / 1000, timezone.utc)

To show a time inside a Discord message rather than decode one, use the Discord timestamp builder.

Source: Discord developer docs: Snowflakes

Source: X developer docs: X IDs

Source: Twitter snowflake source (archived), bit layout

Last updated: