What Is a Unix Timestamp?
A Unix timestamp, also called Epoch time or POSIX time, is the number of seconds that have elapsed since midnight on January 1, 1970 in Coordinated Universal Time (UTC). This date is known as the Unix epoch. Because it is a single integer with no timezone or calendar formatting, it provides a universal, language-agnostic way to represent a specific moment in time, making it the de facto standard for storing dates in databases, APIs, log files and event streams.
Timestamps are popular in software development because they simplify date arithmetic. Calculating the difference between two dates is a simple subtraction, sorting events chronologically is a numeric sort, and converting to any local timezone is a matter of adding an offset. Programming languages universally provide built-in functions to convert between timestamps and human-readable date strings.
One known limitation is the Year 2038 problem (Y2K38). Systems that store Unix time as a signed 32-bit integer will overflow on January 19, 2038, wrapping around to a negative number that represents a date in December 1901. Most modern systems have already migrated to 64-bit integers, which extend the range billions of years into the future, but legacy embedded systems and older codebases may still be affected.
Frequently Asked Questions
What is a Unix timestamp?
A Unix timestamp is the number of seconds since January 1, 1970 00:00:00 UTC (the Unix epoch). It is a timezone-independent integer used across virtually every programming language and operating system to represent a precise moment in time. For example, the timestamp 1700000000 corresponds to November 14, 2023 at 22:13:20 UTC.
Why do some timestamps have 10 digits and others 13?
A 10-digit timestamp counts seconds since the epoch and is the standard format on Unix/Linux systems and in languages like Python and PHP. A 13-digit timestamp counts milliseconds and is the default in JavaScript (Date.now()), Java, and many REST APIs. To convert between them, multiply seconds by 1000 or divide milliseconds by 1000.
How do I get the current timestamp in my programming language?
Most languages make this straightforward. In JavaScript: Math.floor(Date.now() / 1000). In Python: import time; int(time.time()). In PHP: time(). In Java: System.currentTimeMillis() / 1000. In Ruby: Time.now.to_i. In Go: time.Now().Unix(). Each of these returns the number of seconds since January 1, 1970 UTC.
What is the Unix epoch?
The Unix epoch is the reference point from which Unix timestamps are measured: January 1, 1970 at 00:00:00 Coordinated Universal Time (UTC). It was chosen as a convenient, round date when Unix was being developed at Bell Labs in the early 1970s. Every Unix timestamp is simply the number of seconds (or milliseconds) that have elapsed since this moment.
What is the Year 2038 problem?
The Year 2038 problem (Y2K38) affects systems that store Unix timestamps as a signed 32-bit integer. The maximum value a signed 32-bit integer can hold is 2,147,483,647, which corresponds to January 19, 2038 at 03:14:07 UTC. After that moment, the integer overflows and wraps to a negative number, causing the date to jump back to December 1901. Most modern systems have migrated to 64-bit integers, but legacy embedded systems and older codebases may still be vulnerable.
Should I use seconds or milliseconds for timestamps?
It depends on your platform and precision requirements. Traditional Unix systems and languages like Python and PHP use seconds (10-digit timestamps), while JavaScript, Java, and many REST APIs default to milliseconds (13-digit timestamps). If you need sub-second precision for event ordering or animation timing, use milliseconds. For most database storage and API contracts, seconds are sufficient and save space.
How do time zones affect Unix timestamps?
Unix timestamps are always relative to UTC and are not affected by time zones. A given moment in time has the same Unix timestamp regardless of whether you are in New York, London, or Tokyo. Time zones only matter when you convert a timestamp to a human-readable date string, at which point you apply an offset to display the correct local time. This timezone independence is one of the main reasons timestamps are preferred for storing dates in software.