What Is a Unix Timestamp and How Do You Convert It?
You have probably seen a number like 1793059200 in a log file, an API response, or a database column. At first glance, it looks random. In reality, it represents a specific moment in time.
A Unix timestamp counts the seconds elapsed since a fixed starting point: January 1, 1970, at 00:00:00 UTC. Computers use timestamps because they make it easier to compare dates, calculate time differences, and exchange time values between systems.
This guide explains how Unix timestamps work and shows you how to convert them into readable dates and back using JavaScript, Python, and command-line tools. You will also learn about seconds versus milliseconds, time zones, and common timestamp mistakes.
What Is a Unix Timestamp?
A Unix timestamp is a numerical representation of a point in time. Traditionally, it counts the seconds elapsed since January 1, 1970, at 00:00:00 UTC. This starting point is called the Unix epoch.
For example:
0represents the Unix epoch itself.86400represents one day after the epoch.172800represents two days after the epoch.-86400represents one day before the epoch.
This numerical format is convenient because software can compare timestamps and calculate elapsed time using arithmetic.
For example, subtracting an earlier timestamp from a later one gives the difference in seconds, provided both values use the same unit and time convention.
Unix Epoch Time
Unix epoch time is another name for the time representation associated with the Unix epoch.
The epoch provides a shared reference point, allowing different systems to represent moments in time using numerical values rather than formatted dates.
For example, the date 1970-01-01 00:00:00 UTC corresponds to timestamp 0. A timestamp of 86400 corresponds to the same clock time on the following day under conventional Unix-time calculations.
Dates before the epoch can be represented by negative timestamps when the programming language or system supports them.
The Unix epoch became widely adopted through Unix and related computing systems. Today, Unix timestamps are commonly used in application programming interfaces (APIs), databases, server logs, analytics systems, and scheduled tasks.
Unix Timestamp Format
A Unix timestamp is usually represented as an integer containing the number of elapsed seconds. Some systems support fractional seconds or store time in other units, such as milliseconds or microseconds.
Unlike a formatted date, a timestamp does not contain a written month, day, or time-zone label. Its meaning depends on the epoch, unit, and time convention used by the system.
For example:
1793059200
This value represents October 27, 2026, at 00:00:00 UTC when interpreted as Unix time in seconds.
Because timestamps are numerical, they are useful for:
- Comparing when events occurred.
- Calculating time intervals.
- Filtering database records by date.
- Recording event times in logs.
- Passing dates between applications and APIs.
Always confirm the unit before interpreting a timestamp. A value expressed in milliseconds cannot be handled in the same way as one expressed in seconds.
Unix Timestamp in Seconds vs. Milliseconds
Traditional Unix timestamps use seconds. Many modern applications also use milliseconds to represent time with finer resolution.
Here is the same moment represented in both units:
| Unit | Timestamp |
|---|---|
| Seconds | 1793059200 |
| Milliseconds | 1793059200000 |
The conversion is straightforward:
- Seconds to milliseconds: Multiply by 1,000.
- Milliseconds to seconds: Divide by 1,000.
For example:
1793059200 × 1000 = 1793059200000
The reverse calculation is:
1793059200000 ÷ 1000 = 1793059200
JavaScript’s Date API uses milliseconds, while Python’s common Unix timestamp functions use seconds. This difference is a frequent source of bugs.
A 10-digit value often represents seconds for dates around the present day, while a 13-digit value often represents milliseconds. However, digit count is only a clue, not a universal rule. Older dates, future dates, negative values, and other time units can have different lengths.
Convert Unix Timestamp to Date
Converting a timestamp to a readable date means interpreting the numerical value using the correct unit and displaying the corresponding moment in a chosen time zone.
Unix Timestamp to Human-Readable Date
Consider this timestamp:
1793059200
Interpreted as seconds since the Unix epoch, it represents:
October 27, 2026, at 00:00:00 UTC
You can display the same moment in another time zone, where the local clock time and sometimes the calendar date will differ. The underlying instant remains the same.
For reliable results, decide whether you want UTC or a particular local time zone before formatting the date.
Unix Timestamp JavaScript
JavaScript’s Date constructor expects milliseconds when you pass a numerical timestamp. If your value is in seconds, multiply it by 1,000.
const ts = 1793059200; const date = new Date(ts * 1000); console.log(date.toISOString()); // 2026-10-27T00:00:00.000Z
The toISOString() method returns a date-time string in UTC. The Z at the end indicates UTC.
If your timestamp already uses milliseconds, do not multiply it by 1,000 again.
Unix Timestamp Python
Python’s datetime module provides fromtimestamp() to convert a Unix timestamp into a date-time object.
Pass timezone.utc when you want the result in UTC rather than your computer’s local time zone.
from datetime import datetime, timezone ts = 1793059200 date = datetime.fromtimestamp(ts, tz=timezone.utc) print(date) # 2026-10-27 00:00:00+00:00
The +00:00 suffix indicates that the date-time object uses a UTC offset of zero.
This approach is useful for processing timestamps consistently across servers in different locations.
Convert Date to Unix Timestamp
The reverse conversion is also common. You may have a date and need its timestamp for an API request, database query, event record, or cache expiration.
The important detail is that a date-time must identify a specific moment. If you are starting with a local date and time, you need to know the relevant time zone before converting it.
How to Calculate a Unix Timestamp
You can calculate a timestamp manually by counting the elapsed days since January 1, 1970, and then adding the seconds within the day.
For October 27, 2026, at midnight UTC:
- The elapsed time from January 1, 1970, to January 1, 2026, is 56 years.
- Those years contain 20,454 days, including 14 leap days.
- October 27 is 299 days after January 1, 2026.
- The total is 20,753 elapsed days.
- Multiply by 86,400 seconds per day.
20753 × 86400 = 1793059200
The resulting timestamp is 1793059200.
In practice, programming language functions are safer and more convenient than calculating dates manually.
Convert a Date to a Unix Timestamp in JavaScript
JavaScript’s Date.UTC() creates a timestamp in milliseconds for the supplied UTC date and time. Divide the result by 1,000 to get seconds.
const timestamp = Math.floor( Date.UTC(2026, 9, 27) / 1000 ); console.log(timestamp); // 1793059200
JavaScript numbers months from 0 to 11, rather than 1 to 12. That means January is 0, October is 9, and December is 11.
This example uses midnight UTC. If you need to convert a local time, use an appropriate time-zone-aware approach rather than treating local time as UTC.
Convert a Date to a Unix Timestamp in Python
Python’s datetime objects can convert dates and times into Unix timestamps using .timestamp().
from datetime import datetime, timezone date = datetime(2026, 10, 27, tzinfo=timezone.utc) timestamp = int(date.timestamp()) print(timestamp) # 1793059200
The example explicitly sets the time zone to UTC, so the result does not depend on the machine’s local time zone.
If your date-time represents local time, make sure it has the correct time-zone information before converting it.
Current Unix Timestamp and Unix Timestamp UTC
A current Unix timestamp changes continuously as time passes. You can retrieve it directly in JavaScript, Python, or a Unix-like terminal.
JavaScript
const timestamp = Math.floor(Date.now() / 1000); console.log(timestamp);
Date.now() returns milliseconds since the epoch, so dividing by 1,000 converts the value to seconds. Math.floor() removes the fractional part.
Python
import time timestamp = int(time.time()) print(timestamp)
Python’s time.time() returns the time in seconds as a floating-point number. Converting it to an integer removes the fractional portion.
Linux or macOS terminal
date +%s
On common GNU and BSD-based systems, this command prints the current Unix timestamp in seconds. Available options and behavior can vary across platforms.
If you are checking a live timestamp, remember that the value changes from one second to the next. A value retrieved now will not necessarily match one retrieved a moment later.
Why a Unix Timestamp Is Usually Treated as UTC
A Unix timestamp represents a moment relative to the Unix epoch. It does not contain a local time-zone label.
This is why two servers in different countries can represent the same instant with the same timestamp, assuming they use the same unit and time convention.
Time zones become important when converting that instant into a human-readable date and clock time.
For example, the same timestamp might display as midnight UTC in one application and as a different local time in another. Neither display necessarily changes the underlying instant.
A useful practice is to keep timestamps in a consistent representation when exchanging event times between systems, then apply the appropriate time zone when displaying them to users.
One qualification is important: Unix-time implementations generally do not represent leap seconds as separate, ordinary timestamp values. Real systems may handle leap seconds or adjust their clocks in different ways, so timestamps are not a perfect substitute for every scientific or precision timekeeping application.
Use a Unix Time Converter and Avoid Common Mistakes
An online Unix timestamp converter is useful when you want to inspect a value quickly. Most converters let you enter a timestamp and see the corresponding date, or enter a date to get a timestamp.
These tools can help when debugging logs, checking API responses, or investigating database records. For repeated conversions, built-in programming language functions are usually more convenient.
Watch for these common mistakes.
1. Mixing Seconds and Milliseconds
This is one of the most frequent timestamp errors.
If you pass a seconds-based timestamp directly to JavaScript’s Date constructor, JavaScript interprets it as milliseconds. The result will usually appear close to January 1970 rather than the intended modern date.
Check the unit and convert it when necessary.
2. Ignoring Time Zones
A timestamp represents an instant, but its displayed clock time depends on the time zone used for formatting.
When comparing dates across systems, confirm whether each output is in UTC or local time. Also account for daylight saving time when working with local dates in regions that observe it.
3. Using a Signed 32-Bit Integer
A signed 32-bit integer can store a maximum value of 2147483647. For Unix timestamps in seconds, that corresponds to January 19, 2038, at 03:14:07 UTC.
Systems that rely on signed 32-bit timestamp storage can encounter overflow problems beyond this limit. This is commonly known as the Year 2038 problem. (MIT Kerberos documentation explains the issue)
For new systems, use suitable 64-bit timestamp storage or a date-time type with an appropriate range. Also check the limits of any database columns, APIs, file formats, or older libraries that handle the value.
4. Forgetting That JavaScript Months Start at Zero
JavaScript’s Date.UTC() uses zero-based month numbers. October is 9, not 10.
If you enter 10 expecting October, your date will fall in November. Double-check month values whenever constructing dates manually.
5. Converting a Local Date as If It Were UTC
A date such as October 27 at 9:00 AM is not enough to identify a unique moment unless you know its time zone.
If the original time is local, interpret it in the correct time zone before converting it into a timestamp. Otherwise, your result may be offset by several hours.
Conclusion
A Unix timestamp represents a moment in time relative to the Unix epoch, January 1, 1970, at 00:00:00 UTC. It is useful for comparing dates, recording events, processing logs, and exchanging time values between applications.
Before converting a timestamp, check whether it uses seconds or milliseconds. In JavaScript, use new Date(timestamp * 1000) for seconds-based values. In Python, use datetime.fromtimestamp() with an explicit time zone when you need a predictable UTC result.
When converting a date back into a timestamp, make sure the original date-time has the correct time-zone information. For new systems, choose suitable timestamp storage and be aware of the Year 2038 limitation in older 32-bit implementations.
Once you understand the epoch, units, and time-zone rules, Unix timestamp conversions become much easier to handle correctly.
Frequently asked questions
What is a Unix timestamp in simple terms?
A Unix timestamp is a number representing the time elapsed since January 1, 1970, at 00:00:00 UTC. It gives software a convenient way to represent and compare moments in time.
How many digits does a Unix timestamp have?
There is no fixed number of digits. Around the present day, timestamps in seconds commonly have 10 digits, while timestamps in milliseconds commonly have 13. The number of digits depends on the date and the unit.
Does a Unix timestamp include leap seconds?
Conventional Unix timestamps do not represent leap seconds as separate, ordinary seconds. However, system clocks and implementations can handle leap seconds differently, so behavior may vary in precision timekeeping environments.
Can a Unix timestamp be negative?
Yes. Negative timestamps represent moments before the Unix epoch, provided the programming language, database, and operating system support the relevant date range.
What is the Unix timestamp for right now?
The value changes continuously. Run Math.floor(Date.now() / 1000) in JavaScript or int(time.time()) in Python to retrieve a current timestamp in seconds.
What is the difference between Unix time in seconds and milliseconds?
Seconds-based timestamps count elapsed seconds since the epoch. Millisecond-based timestamps count milliseconds. To convert seconds to milliseconds, multiply by 1,000; to convert milliseconds to seconds, divide by 1,000.
How do I convert a Unix timestamp to a date in JavaScript?
Use new Date(timestamp * 1000) when the timestamp is in seconds. Then call .toISOString() to display the result in UTC.
How do I convert a Unix timestamp to a date in Python?
Use datetime.fromtimestamp(timestamp, tz=timezone.utc) from Python’s datetime module. This converts a seconds-based timestamp to a date-time object in UTC.
Is a Unix timestamp the same in every time zone?
The underlying timestamp represents the same instant regardless of the viewer’s time zone. However, the formatted date and clock time can differ when the instant is displayed in different time zones.
What is the Year 2038 problem?
The Year 2038 problem affects systems that store Unix timestamps in signed 32-bit integers. The largest positive value is 2147483647, representing January 19, 2038, at 03:14:07 UTC. Systems using this storage format may overflow after that point unless they are updated.