HOW UNIX TIMESTAMPS WORK
WHAT IS UNIX TIME?
Unix time (also called epoch time, POSIX time, or Unix timestamp) is a system for describing points in time. It represents the number of seconds that have elapsed since the "Unix epoch" - January 1, 1970, 00:00:00 UTC - not counting leap seconds.
KEY FACTS:
- • Epoch Start: January 1, 1970, 00:00:00 UTC
- • Unit: Seconds (though milliseconds and microseconds are also used)
- • Timezone: Always based on UTC (Coordinated Universal Time)
- • Range: Can represent dates from 1970 to 2038 (32-bit) or beyond (64-bit)
TIMESTAMP FORMATS
1. SECONDS (10 DIGITS)
The standard Unix timestamp format representing seconds since epoch.
Represents: January 27, 2025, 16:41:12 UTC
2. MILLISECONDS (13 DIGITS)
Used in JavaScript and many web applications for higher precision.
Same time as above but with millisecond precision
3. MICROSECONDS (16 DIGITS)
Used in high-precision systems and some databases.
Same time with microsecond precision
CONVERSION PROCESS
EPOCH TO DATE
Converting a Unix timestamp to a human-readable date involves these steps:
- Identify the timestamp format (seconds, milliseconds, or microseconds)
- Convert to milliseconds if necessary (JavaScript Date objects use milliseconds)
- Create a Date object from the timestamp
- Format the date according to the desired timezone and format
DATE TO EPOCH
Converting a date to Unix timestamp:
- Parse the input date string or date components
- Create a Date object (automatically handles timezone conversion to UTC)
- Get the timestamp in milliseconds using getTime()
- Convert to seconds by dividing by 1000 (if seconds format is desired)
TIMEZONE HANDLING
Unix timestamps are always in UTC, but when displaying dates to users, we often need to convert to local timezones:
UTC & AMERICAS:
- UTC: The standard reference timezone (GMT+0)
- EST: Eastern Standard Time (UTC-5)
- CST: Central Standard Time (UTC-6)
- PST: Pacific Standard Time (UTC-8)
EUROPE & ASIA:
- London: Greenwich Mean Time (UTC+0)
- Paris: Central European Time (UTC+1)
- Tokyo: Japan Standard Time (UTC+9)
- Shanghai: China Standard Time (UTC+8)
LIMITATIONS
YEAR 2038 PROBLEM
32-bit systems will face an overflow issue on January 19, 2038, at 03:14:07 UTC. Modern 64-bit systems extend this limit far into the future.
LEAP SECONDS
Unix time doesn't account for leap seconds, which are occasionally added to UTC. This means Unix time can be off by several seconds from actual UTC.