Skip to content

Instantly share code, notes, and snippets.

@msramalho
Created March 7, 2025 13:14
Show Gist options
  • Save msramalho/1bb9fb010f67d41bd8e2696fbb704b84 to your computer and use it in GitHub Desktop.
Save msramalho/1bb9fb010f67d41bd8e2696fbb704b84 to your computer and use it in GitHub Desktop.
Get TikTok video posted date and time from tiktok video id, python code

inspired by: https://github.com/bellingcat/tiktok-timestamp

from datetime import datetime

def tiktok_id_to_timestamp(video_id: int) -> datetime:
    """Convert a TikTok video ID to datetime object."""
    binary_id = bin(video_id)[2:]  # Convert to binary and remove '0b'
    timestamp_bits = binary_id[:31]  # Take the first 31 bits
    timestamp = int(timestamp_bits, 2)  # Convert back to decimal
    return datetime.fromtimestamp(timestamp, tz=timezone.utc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment