Convert Twitter ID to Unix Timestamp

📌 Try these examples:
TWITTER SNOWFLAKE ID
⏱️ UNIX TIMESTAMP (milliseconds)
⏱️ UNIX TIMESTAMP (seconds)
📅 HUMAN-READABLE DATE
🕐 ISO 8601 FORMAT

Last updated

How Twitter Snowflake ID to Timestamp Conversion Works

Twitter Snowflake IDs are 64-bit integers where the first 41 bits encode the timestamp. To extract the Unix timestamp:

Extraction Formula:

timestamp_ms = (snowflake_id >> 22) + 1288834974657

Steps:

  1. Right-shift the Snowflake ID by 22 bits to extract timestamp bits
  2. Add Twitter's epoch: 1288834974657 (Nov 4, 2010, 01:42:54 UTC)
  3. Result is Unix timestamp in milliseconds
  4. Divide by 1000 for Unix timestamp in seconds

Twitter Snowflake ID to Timestamp — Examples

Every Twitter Snowflake ID encodes the exact millisecond of creation in its most significant bits. Here are complete examples for converting Twitter IDs to timestamps in multiple languages and formats.

JavaScript

// JavaScript — Snowflake ID to timestamp
const TWITTER_EPOCH = 1288834974657n;

function snowflakeToTimestamp(idStr) {
  const id = BigInt(idStr);
  const timestampMs = (id >> 22n) + TWITTER_EPOCH;
  const date = new Date(Number(timestampMs));
  
  return {
    utc:         date.toUTCString(),
    iso8601:     date.toISOString(),
    unixMs:      timestampMs.toString(),
    unixSeconds: Math.floor(Number(timestampMs) / 1000),
    local:       date.toLocaleString()
  };
}

// Examples
console.log(snowflakeToTimestamp("1529877576591609861"));
console.log(snowflakeToTimestamp("1700000000000000000"));

Python

# Python — Snowflake ID to timestamp
from datetime import datetime, timezone

TWITTER_EPOCH_MS = 1288834974657

def snowflake_to_timestamp(id_str):
    id_val = int(id_str)
    ts_ms = (id_val >> 22) + TWITTER_EPOCH_MS
    dt = datetime.fromtimestamp(ts_ms / 1000, tz=timezone.utc)
    
    return {
        "utc": dt.strftime("%Y-%m-%d %H:%M:%S UTC"),
        "iso8601": dt.isoformat(),
        "unix_ms": ts_ms,
        "unix_s": ts_ms // 1000
    }

print(snowflake_to_timestamp("1529877576591609861"))

All Output Formats

// Show all common timestamp formats for a given ID
function allFormats(idStr) {
  const id = BigInt(idStr);
  const TWITTER_EPOCH = 1288834974657n;
  const tsMs = (id >> 22n) + TWITTER_EPOCH;
  const date = new Date(Number(tsMs));
  
  return {
    "UTC":          date.toUTCString(),
    "ISO 8601":     date.toISOString(),
    "Unix (ms)":    tsMs.toString(),
    "Unix (s)":     Math.floor(Number(tsMs) / 1000).toString(),
    "Date only":    date.toISOString().split("T")[0],
    "Time only":    date.toISOString().split("T")[1].replace("Z", " UTC"),
    "Local":        date.toLocaleString(),
    "RFC 2822":     date.toUTCString()
  };
}

const formats = allFormats("1529877576591609861");
Object.entries(formats).forEach(([fmt, val]) => {
  console.log(`${fmt.padEnd(12)}: ${val}`);
});

Reverse: Timestamp to Snowflake ID

// Convert a timestamp to the minimum Snowflake ID for that moment
// Essential for Twitter API since_id / max_id parameters

function timestampToSnowflakeId(date) {
  const TWITTER_EPOCH = 1288834974657n;
  const tsMs = BigInt(date.getTime()) - TWITTER_EPOCH;
  
  if (tsMs < 0n) {
    throw new Error("Date is before Twitter's Snowflake epoch (Nov 4, 2010)");
  }
  
  // Minimum ID: all lower 22 bits = 0
  const minId = (tsMs << 22n).toString();
  // Maximum ID: all lower 22 bits = 1
  const maxId = ((tsMs << 22n) | 0x3FFFFFn).toString();
  
  return { minId, maxId };
}

// Example: get ID range for a specific date
const date = new Date("2023-06-15T12:00:00Z");
const { minId, maxId } = timestampToSnowflakeId(date);
console.log("Min ID:", minId);
console.log("Max ID:", maxId);

Batch Conversion

# Python — batch convert IDs to timestamps
from datetime import datetime, timezone
import csv

TWITTER_EPOCH_MS = 1288834974657

def batch_convert(id_list):
    results = []
    for id_str in id_list:
        id_val = int(id_str.strip())
        ts_ms = (id_val >> 22) + TWITTER_EPOCH_MS
        dt = datetime.fromtimestamp(ts_ms / 1000, tz=timezone.utc)
        results.append({
            "id": id_str,
            "created_at_utc": dt.isoformat(),
            "unix_ms": ts_ms,
            "unix_s": ts_ms // 1000
        })
    return results

# Process a list of IDs
ids = [
    "1529877576591609861",
    "1700000000000000000",
    "1800000000000000000",
    "1900000000000000000",
]

results = batch_convert(ids)

# Export to CSV
with open("timestamps.csv", "w", newline="") as f:
    writer = csv.DictWriter(f, fieldnames=results[0].keys())
    writer.writeheader()
    writer.writerows(results)

print(f"Exported {len(results)} rows")

Using Timestamps for API Pagination

# Python — use ID-based pagination to fetch tweets from a time period
import requests
from datetime import datetime, timezone

TWITTER_EPOCH_MS = 1288834974657

def date_to_min_id(dt):
    ts_ms = int(dt.timestamp() * 1000) - TWITTER_EPOCH_MS
    return str(ts_ms << 22)

def fetch_tweets_in_period(query, start_dt, end_dt, bearer_token):
    since_id = date_to_min_id(start_dt)
    max_id   = date_to_min_id(end_dt)
    
    headers = {"Authorization": f"Bearer {bearer_token}"}
    params = {
        "query": query,
        "since_id": since_id,
        "max_results": 100,
        "tweet.fields": "created_at,author_id,text"
    }
    
    response = requests.get(
        "https://api.twitter.com/2/tweets/search/recent",
        headers=headers,
        params=params
    )
    return response.json()

# Fetch tweets from a specific week
start = datetime(2023, 6, 1, tzinfo=timezone.utc)
end   = datetime(2023, 6, 7, tzinfo=timezone.utc)
data  = fetch_tweets_in_period("#python", start, end, "YOUR_TOKEN")

Tweet Age Calculation

// Calculate how old a tweet is from its ID
function getTweetAge(idStr) {
  const id = BigInt(idStr);
  const TWITTER_EPOCH = 1288834974657n;
  const tsMs = Number((id >> 22n) + TWITTER_EPOCH);
  
  const now = Date.now();
  const ageMs = now - tsMs;
  
  const seconds = Math.floor(ageMs / 1000);
  const minutes = Math.floor(seconds / 60);
  const hours   = Math.floor(minutes / 60);
  const days    = Math.floor(hours / 24);
  const years   = Math.floor(days / 365);
  
  if (years > 0)   return `${years} year${years > 1 ? "s" : ""} ago`;
  if (days > 0)    return `${days} day${days > 1 ? "s" : ""} ago`;
  if (hours > 0)   return `${hours} hour${hours > 1 ? "s" : ""} ago`;
  if (minutes > 0) return `${minutes} minute${minutes > 1 ? "s" : ""} ago`;
  return `${seconds} second${seconds !== 1 ? "s" : ""} ago`;
}

console.log(getTweetAge("1529877576591609861")); // e.g., "3 years ago"

The Snowflake ID to timestamp conversion is deterministic and precise to the millisecond. The same ID always produces the same timestamp, making it a reliable way to verify when any Twitter content was created.

Why Extract Timestamps from Twitter IDs?

📊

Time-Series Analysis

Use timestamps for chronological sorting and timeline analysis of tweets.

🤖

API Integration

Convert Twitter IDs to timestamps for database storage and API responses.

🔍

Forensic Analysis

Verify exact tweet posting times for investigations and fact-checking.

Code Examples: Extract Timestamp from Twitter ID

JavaScript
// JavaScript - Extract Unix timestamp from Twitter Snowflake ID
function extractTimestamp(snowflakeId) {
  const TWITTER_EPOCH = 1288834974657n;
  const id = BigInt(snowflakeId);
  const timestampMs = Number((id >> 22n) + TWITTER_EPOCH);
  const timestampSec = Math.floor(timestampMs / 1000);
  
  return {
    milliseconds: timestampMs,
    seconds: timestampSec,
    date: new Date(timestampMs)
  };
}

// Example
const result = extractTimestamp('1382350606417817604');
console.log(result.milliseconds); // 1618414206657
console.log(result.seconds);      // 1618414206
console.log(result.date.toISOString()); // 2021-04-14T15:30:06.657Z
Python
# Python - Extract Unix timestamp from Twitter Snowflake ID
from datetime import datetime

def extract_timestamp(snowflake_id):
    TWITTER_EPOCH = 1288834974657
    timestamp_ms = ((int(snowflake_id) >> 22) + TWITTER_EPOCH)
    timestamp_sec = timestamp_ms // 1000
    
    return {
        'milliseconds': timestamp_ms,
        'seconds': timestamp_sec,
        'date': datetime.fromtimestamp(timestamp_sec)
    }

# Example
result = extract_timestamp('1382350606417817604')
print(result['milliseconds'])  # 1618414206657
print(result['seconds'])       # 1618414206
print(result['date'].isoformat())  # 2021-04-14T15:30:06

Understanding Twitter's Epoch

Twitter uses a custom epoch of November 4, 2010, 01:42:54 UTC (1288834974657 milliseconds since Unix epoch). This custom epoch:

Timestamp Precision

Millisecond Precision: Twitter Snowflake IDs store timestamps with millisecond precision, making them accurate to 1/1000th of a second.

Why it matters: This precision allows for:

Frequently Asked Questions

Q: What's the difference between milliseconds and seconds timestamp?

A: Milliseconds timestamp includes 3 extra digits for sub-second precision. Divide by 1000 to convert to seconds. Twitter stores milliseconds for higher accuracy.

Q: Can I extract timestamps from deleted tweets?

A: Yes! The timestamp is encoded in the ID itself, so even if a tweet is deleted, you can still extract when it was originally posted.

Q: Are Twitter user IDs also Snowflake IDs?

A: Yes, Twitter user IDs use the same Snowflake format. Extract the timestamp to see when an account was created.

Frequently Asked Questions

Twitter Snowflake IDs encode the timestamp in the first 41 bits. To extract it: shift the ID right by 22 bits, add Twitter's epoch (1288834974657), and you get the Unix timestamp in milliseconds. Our tool does this automatically - just paste the Twitter ID.

Twitter Snowflake IDs store timestamps as milliseconds since Twitter's custom epoch (November 4, 2010, 01:42:54 UTC). The timestamp occupies 41 bits, allowing for ~69 years of unique IDs from 2010 to 2079.

Yes! Extract the timestamp from the Snowflake ID by shifting right 22 bits and adding 1288834974657 (Twitter's epoch). This gives you the Unix timestamp in milliseconds when the tweet or account was created.