Unix Time vs ISO 8601
Unix time and ISO 8601 are two common ways to represent dates and times in software. Learn how they work, how they differ, and when to use each format.
Dates and times are represented in many different ways in software. Two of the most common are Unix time and ISO 8601. They solve related problems, but they are designed for different purposes. Unix time represents a moment as a numerical count of time units from a defined epoch, while ISO 8601 provides a standardized textual format for representing dates and times in a way that is easier for humans to read.
Understanding the difference matters when working with APIs, databases, logs, JavaScript applications, distributed systems, and data exchanged between different platforms. A Unix timestamp is compact and easy for computers to compare, while an ISO 8601 timestamp can communicate the calendar date, time, and sometimes the UTC offset directly in the value.
What Is Unix Time?
Unix time, also called Unix timestamp or POSIX time, represents time as the number of seconds that have elapsed since the Unix epoch. The Unix epoch is 1970-01-01 at 00:00:00 UTC. For example, the Unix timestamp 0 represents the beginning of this epoch.
Unix timestamp: 0
UTC date: 1970-01-01 00:00:00Modern Unix timestamps are usually positive integers because they represent dates after 1970. For example, a timestamp such as 1704067200 represents a specific instant in time. Dates before the Unix epoch can also be represented using negative timestamps in systems that support them.
Unix time is primarily intended to provide a simple numerical representation of an instant. Because timestamps are numbers, they are convenient for comparison, sorting, arithmetic, storage, and calculations.
What Is ISO 8601?
ISO 8601 is an international standard for representing dates and times. Unlike Unix time, it does not define one single numeric timestamp format. Instead, it specifies standardized textual representations for dates, times, date-times, time intervals, durations, and related concepts.
2026-08-28T12:30:00ZThe example uses a four-digit year, two-digit month, and two-digit day, followed by the letter T and a time. The Z indicates that the time is expressed in UTC. ISO 8601 values can also include an explicit UTC offset such as +03:00.
2026-08-28T15:30:00+03:00ISO 8601 is especially useful when a timestamp needs to be understandable by both people and software. Its structure makes the individual components of a date and time visible instead of hiding them inside a single integer.
Unix Time vs ISO 8601 at a Glance
| Feature | Unix Time | ISO 8601 |
|---|---|---|
| Representation | Numeric timestamp | Structured text |
| Epoch | 1970-01-01 00:00:00 UTC | No single epoch |
| Human readability | Low | High |
| Sorting | Simple numeric sorting | Standard date-time ordering when normalized |
| Timezone information | Not included in the value itself | Can include UTC or an explicit offset |
| Typical use | Storage, calculations, identifiers, APIs | APIs, documents, logs, human-readable data |
The Main Difference Between Unix Time and ISO 8601
The fundamental difference is how the two systems communicate a point in time. Unix time converts a moment into a number relative to the Unix epoch. ISO 8601 expresses date and time components using a standardized textual structure.
For example, the same instant can be represented as a Unix timestamp and as an ISO 8601 timestamp:
Unix time: 1787918400
ISO 8601: 2026-08-28T12:00:00ZThese values are not competing clocks. They can describe the same instant using different representations. Converting between them does not change the underlying moment in time; it changes how that moment is encoded.
Unix Time Is Based on an Epoch
A Unix timestamp is defined relative to a fixed starting point. This makes arithmetic straightforward. If one event has timestamp 1700000000 and another has timestamp 1700003600, the difference is 3600 seconds, or one hour.
1700003600 - 1700000000 = 3600 secondsThis property makes Unix timestamps convenient for measuring elapsed time. Applications can subtract two timestamps without first parsing separate year, month, day, hour, and timezone fields.
ISO 8601 Makes Date Components Explicit
An ISO 8601 date-time makes its calendar components visible. In a value such as 2026-08-28T12:30:00Z, the year, month, day, hour, minute, and second can be identified directly.
This is useful in API responses, configuration files, logs, database exports, documentation, and debugging because developers can often understand the timestamp without converting a large number into a calendar date.
Timezone Information
Timezone handling is one of the most important differences between the representations. A Unix timestamp identifies an instant relative to UTC and does not contain a separate timezone or UTC offset field. The same Unix timestamp therefore refers to the same instant regardless of where it is displayed.
An ISO 8601 date-time can explicitly include UTC or an offset. For example, these two values represent the same instant:
2026-08-28T12:00:00Z
2026-08-28T15:00:00+03:00The first value expresses the instant in UTC, while the second expresses it using a UTC+03:00 offset. The local clock times differ, but the underlying instant is the same.
Seconds vs Milliseconds
One common source of bugs is confusing Unix timestamps measured in seconds with timestamps measured in milliseconds. The Unix and POSIX concepts are traditionally based on seconds, but many programming environments use milliseconds for their date APIs.
const milliseconds = Date.now();
const seconds = Math.floor(Date.now() / 1000);
console.log(milliseconds);
console.log(seconds);For example, JavaScript's Date.now() returns the number of milliseconds since the Unix epoch. A Unix timestamp API or database field may instead expect seconds. Passing one unit where the other is expected can produce dates thousands of times too large or too small.
Which Format Is More Human-Readable?
ISO 8601 is much easier for humans to interpret. A developer can immediately recognize 2026-08-28T12:30:00Z as a date and time. A value such as 178791? cannot be interpreted reliably without knowing the timestamp unit and converting it.
This makes ISO 8601 particularly useful in logs and API responses where developers may need to inspect values manually. Unix timestamps are more compact, but they generally require a conversion step before a person can understand them as a calendar date.
Which Format Is Better for Calculations?
Unix timestamps are convenient for basic calculations involving elapsed time. Subtracting two timestamps directly produces a duration in the timestamp's unit. This is useful for measuring timeouts, expiration periods, delays, and event intervals.
ISO 8601 values can also be parsed and compared by modern programming languages and libraries, but the textual representation normally has to be parsed into a date-time object first. After parsing, applications can perform calendar-aware operations using the resulting date-time representation.
Which Format Should APIs Use?
There is no universal rule that every API must use one representation. ISO 8601 date-times are often a good choice for public APIs because they are self-describing and easier for developers to inspect. A value such as 2026-08-28T12:30:00Z clearly communicates its structure and UTC status.
Unix timestamps can be useful when an API is optimized for compact numeric data, simple arithmetic, or compatibility with systems that already use epoch-based timestamps. The important part is to document the unit and timezone semantics clearly.
Which Format Should Databases Use?
Database storage should generally use an appropriate native date-time type when the database provides one. Native temporal types can preserve information and provide useful date and time operations without forcing applications to treat timestamps as arbitrary strings or integers.
Unix timestamps can still be useful as numeric fields when an application specifically needs epoch-based values. ISO 8601 strings can be convenient for interchange and exports, but storing date-times purely as strings requires careful validation and consistent formatting.
Unix Time and ISO 8601 in JavaScript
JavaScript's Date object internally represents a date as a number of milliseconds from the Unix epoch. This makes conversion between JavaScript dates, Unix timestamps, and ISO 8601 strings relatively straightforward.
const date = new Date("2026-08-28T12:30:00Z");
const iso = date.toISOString();
const unixSeconds = Math.floor(date.getTime() / 1000);
console.log(iso);
console.log(unixSeconds);The toISOString() method produces an ISO-style UTC representation, while getTime() returns milliseconds since the Unix epoch. Dividing by 1000 converts milliseconds to seconds when a conventional Unix timestamp is required.
Common Conversion Mistakes
- Confusing seconds with milliseconds.
- Assuming a Unix timestamp contains timezone information.
- Treating an ISO 8601 local time without an offset as unambiguous.
- Converting timestamps without checking the expected precision.
- Storing date-time strings in inconsistent formats.
- Forgetting that displaying an instant in a local timezone can change the visible clock time without changing the instant.
Another common mistake is assuming that every ISO 8601 value represents UTC. ISO 8601 can represent local date-times and date-times with explicit offsets. For applications where the exact instant matters, the timezone or UTC offset should be handled explicitly.
Unix Time vs ISO 8601: When to Use Each
| Situation | Recommended Representation | Reason |
|---|---|---|
| Human-readable API response | ISO 8601 | Easy to inspect and understand |
| Elapsed-time calculations | Unix timestamp | Simple numeric arithmetic |
| Logs | ISO 8601 | Readable and explicit |
| Compact numeric storage | Unix timestamp | Small and easy to process |
| Data exchange | ISO 8601 | Standardized textual representation |
| Legacy epoch-based system | Unix timestamp | Matches existing system conventions |
Are Unix Time and ISO 8601 Compatible?
Yes. They can represent the same moments and can be converted between one another. The conversion requires interpreting the Unix timestamp as an instant and then formatting that instant as an ISO 8601 date-time, or parsing an ISO 8601 date-time and calculating its offset from the Unix epoch.
For example, an application may receive an ISO 8601 timestamp from an API, convert it into an internal date-time object, and then calculate or store an epoch-based value. Another system can later convert that value back into an ISO 8601 representation for display or data exchange.
Unix Time vs ISO 8601: Key Takeaways
- Unix time represents an instant as a count from the Unix epoch.
- ISO 8601 provides standardized textual representations for dates and times.
- Unix timestamps are convenient for numerical comparison and elapsed-time calculations.
- ISO 8601 values are generally easier for humans to read.
- Unix timestamps do not carry a timezone or UTC offset as part of the numeric value.
- ISO 8601 can explicitly include UTC or a UTC offset.
- Always distinguish seconds from milliseconds when working with Unix timestamps.
- Both formats can represent the same instant and can be converted between each other.
What is the difference between Unix time and ISO 8601?
Unix time represents an instant as a numeric count from the Unix epoch, while ISO 8601 represents dates and times using standardized textual formats.
Is Unix time the same as a timestamp?
Unix time is a specific type of timestamp based on the Unix epoch. The word timestamp can also refer to other date and time representations.
Does ISO 8601 use UTC?
ISO 8601 can represent UTC using Z, but it can also represent a time with an explicit UTC offset or other valid date and time forms.
Does a Unix timestamp contain a timezone?
No. A Unix timestamp identifies an instant relative to the Unix epoch and does not contain a separate timezone or UTC offset.
Are Unix timestamps in seconds or milliseconds?
Traditional Unix timestamps use seconds, but many programming APIs use milliseconds. Always check the unit expected by the system or API.
Which is better, Unix time or ISO 8601?
Neither is universally better. Unix time is convenient for numerical calculations and compact storage, while ISO 8601 is usually better for human-readable data exchange and APIs.
Can Unix time and ISO 8601 represent the same moment?
Yes. They are different representations of time and can describe exactly the same instant when converted correctly.
Why is ISO 8601 useful in APIs?
ISO 8601 values are structured, widely recognized, and easier for developers to interpret because the calendar date, time, and UTC offset can be visible in the value.