Guide

Timestamp Guide: Unix Time, Milliseconds, Time Zones, and Conversion Best Practices

A complete guide to timestamps, Unix time, seconds vs. milliseconds, UTC and time zone conversion, ISO 8601, and practical usage in programming, databases, logs, and APIs. Includes an online timestamp converter.

Timestamps appear everywhere in modern software: logs, APIs, databases, analytics events, cache expiration, authentication tokens, and scheduled jobs. At first glance, a timestamp may look like a simple number, such as 1716048000 or 1716048000000. In practice, that number carries important assumptions about precision, time zones, parsing rules, and system compatibility.

If you need to convert a timestamp into a readable date and time, or convert a date and time back into a timestamp, use our Timestamp Converter. It supports common timestamp formats including seconds and milliseconds.

1. What is a Timestamp?

A timestamp is a numeric representation of a specific point in time. The general idea is simple: choose a fixed starting point, then count how much time has passed between that starting point and the target moment.

The most common timestamp format in computing is the Unix timestamp. It uses 1970-01-01 00:00:00 UTC as its starting point, also called the Unix epoch. A Unix timestamp usually counts the number of seconds or milliseconds that have elapsed since that moment.

Common representations include:

FormatExampleMeaning
Unix timestamp in seconds1716048000Seconds since the Unix epoch
Unix timestamp in milliseconds1716048000000Milliseconds since the Unix epoch
ISO 8601 date-time2024-05-18T16:00:00ZA standardized readable date-time string

A timestamp usually does not directly store a time zone such as “New York time” or “Beijing time”. It represents an absolute instant. Time zones only affect how that instant is displayed to humans.

2. Why Does Unix Time Start in 1970?

The Unix epoch is 1970-01-01 00:00:00 UTC. This starting point comes from early Unix system design and has since become a standard across operating systems, programming languages, databases, and network services.

Using a single fixed starting point has several practical benefits:

  • Easy calculation: subtract two timestamps to get a duration.
  • Easy sorting: larger numbers represent later moments.
  • Compact storage: integers are smaller and faster to compare than many date strings.
  • Cross-system compatibility: different platforms can exchange the same numeric representation.

For example, 1716048000 - 1715961600 = 86400, which means the two timestamps are 86400 seconds, or one day, apart.

3. Seconds, Milliseconds, Microseconds, and Nanoseconds

One of the most common timestamp mistakes is mixing up precision. The same moment can be represented in different units, and the number of digits changes accordingly.

PrecisionUnitTypical LengthExample
Seconds1 secondAbout 10 digits1716048000
Milliseconds1/1,000 secondAbout 13 digits1716048000000
Microseconds1/1,000,000 secondAbout 16 digits1716048000000000
Nanoseconds1/1,000,000,000 secondAbout 19 digits1716048000000000000

Different platforms use different defaults:

  • JavaScript Date.now() returns a timestamp in milliseconds.
  • Unix/Linux date +%s returns a timestamp in seconds.
  • Python time.time() returns seconds as a floating-point number.
  • Java System.currentTimeMillis() returns milliseconds.
  • Go time.Now().Unix() returns seconds, while UnixMilli() returns milliseconds.

If you parse a millisecond timestamp as seconds, the result may jump far into the future. If you parse a second timestamp as milliseconds, the result may appear near 1970. This is the most frequent cause of confusing timestamp conversion results.

4. Timestamps and Time Zones

A timestamp identifies an absolute moment. A time zone determines how that moment is shown on a local clock.

The same timestamp can display as different local times:

Time ZoneExample Local Display
UTC2024-05-18 16:00:00
Asia/Shanghai2024-05-19 00:00:00
America/New_York2024-05-18 12:00:00, depending on daylight saving time

These displays all refer to the same instant. The difference comes from time zone offset, not from the timestamp itself.

When working with time zones, keep these rules in mind:

  • Store UTC internally whenever possible.
  • Convert to local time only for display.
  • Avoid hard-coded offsets such as “New York is always UTC-5”; daylight saving time changes that.
  • Make input time zones explicit. A string like 2026-05-18 10:00:00 is ambiguous unless the time zone is known.

5. Timestamps, Date Strings, and ISO 8601

Timestamps are excellent for calculation and storage, but they are not friendly to read. Date strings are readable, but they can be ambiguous. In well-designed systems, both formats often appear together.

Here is how common formats compare:

FormatExampleStrengthRisk
Unix seconds1716048000Compact and easy to sortRequires unit and display-time-zone knowledge
Unix milliseconds1716048000000Common in frontend systemsEasy to confuse with seconds
ISO 8601 UTC2024-05-18T16:00:00ZStandard and unambiguousLonger than an integer
ISO 8601 with offset2024-05-19T00:00:00+08:00Preserves local offsetStill requires correct parsing
Local date string2024/05/19 00:00:00Easy for users to readOften lacks time zone and format rules

For API design, choose one format and document it clearly:

  • Use timestamp when machines need compact numeric values, and clearly state whether the unit is seconds or milliseconds.
  • Use ISO 8601 when external developers need readable, standard date-time values, such as createdAt: "2026-05-18T10:00:00+08:00".
  • Avoid bare strings like 2026-05-18 10:00:00 unless the API documentation explicitly defines the time zone.

6. Timestamps in Common Programming Languages

6.1 JavaScript

// Current timestamp in milliseconds
const ms = Date.now();

// Current timestamp in seconds
const seconds = Math.floor(Date.now() / 1000);

// Convert a millisecond timestamp to a Date
const date = new Date(1716048000000);
console.log(date.toISOString());

JavaScript’s Date constructor expects milliseconds. If your input is a Unix timestamp in seconds, multiply it by 1000 before creating a Date.

6.2 Python

import time
from datetime import datetime, timezone

# Current timestamp in seconds
seconds = int(time.time())

# Current timestamp in milliseconds
milliseconds = int(time.time() * 1000)

# Convert a timestamp to UTC time
dt = datetime.fromtimestamp(seconds, tz=timezone.utc)
print(dt.isoformat())

Python’s datetime.fromtimestamp() may use the local time zone by default. For predictable behavior, pass timezone.utc when you want UTC.

6.3 Java

import java.time.Instant;

long milliseconds = System.currentTimeMillis();
long seconds = Instant.now().getEpochSecond();

Instant instant = Instant.ofEpochMilli(1716048000000L);
System.out.println(instant.toString());

In modern Java, prefer the java.time package. It is clearer and safer than older Date and Calendar APIs, especially for time zones and instants.

6.4 SQL Databases

Database behavior varies. MySQL, PostgreSQL, SQLite, and other databases all provide their own date-time types and functions. Before choosing a storage format, answer these questions:

  • Will the column store an integer timestamp or a native date-time type?
  • Is the unit seconds, milliseconds, or microseconds?
  • Will writes and reads be normalized to UTC?
  • Do you need efficient range queries, indexes, or date-based grouping?

For logs, event streams, and high-frequency data, integer timestamps are compact and easy to sort. For business records such as created_at and updated_at, native database date-time types can be easier to query and format.

7. Common Use Cases for Timestamps

7.1 Logs and Debugging

Server logs often include timestamps because they make sorting, filtering, and aggregation straightforward. In distributed systems, UTC timestamps help avoid confusion when services run in different regions.

7.2 API Data Exchange

APIs commonly include fields such as createdAt, updatedAt, and expiresAt. Whether you choose timestamps or ISO 8601 strings, the API documentation must specify the format, precision, and time zone.

7.3 Cache Expiration and Tokens

Access tokens, verification codes, cache entries, and temporary links often rely on expiration timestamps. The check is simple:

current timestamp > expiration timestamp

If the condition is true, the resource has expired.

7.4 Analytics and Event Tracking

User behavior events, transactions, and telemetry records usually include event time. Timestamps make it easier to sort events, build time windows, calculate funnels, and compare activity across time zones.

7.5 File Names and Version Labels

Backups, exports, and build artifacts often include timestamps in their names, such as backup-20260518-100000.sql or report-1716048000.csv. This prevents name collisions and makes historical tracking easier.

8. Common Timestamp Conversion Mistakes

8.1 Mixing Seconds and Milliseconds

A 10-digit timestamp is usually seconds. A 13-digit timestamp is usually milliseconds. That rule of thumb is helpful, but the reliable source of truth is always the system or API documentation.

8.2 Ignoring Time Zones

When you convert a timestamp to local time, you need to know the display time zone. The same timestamp can appear differently on different computers, browsers, or servers.

8.3 Treating Local Time as UTC

If a user enters 2026-05-18 10:00:00 intending local time, but the system parses it as UTC, the stored moment may be hours off. Forms and APIs should make the time zone visible or implicit by documented rule.

8.4 Daylight Saving Time Errors

Some regions use daylight saving time. Their UTC offset can change depending on the date. For historical timestamps and future schedules, use a reliable time zone database instead of manually adding or subtracting a fixed number of hours.

8.5 The Year 2038 Problem

Older systems that store Unix timestamps in signed 32-bit integers can only represent dates up to around January 19, 2038. Modern systems usually use 64-bit integers, but embedded devices, legacy systems, and older databases may still require attention.

9. How to Choose the Right Time Format

Use the format that matches the job:

ScenarioRecommended Format
Storing absolute momentsUTC date-time or Unix timestamp
Frontend-backend communicationISO 8601 or a timestamp with documented precision
Logs and event streamsUTC timestamp, optionally with ISO 8601 text
User interface displayLocalized date-time based on user time zone
Expiration, countdowns, sortingTimestamp
Emails, reports, contractsHuman-readable date-time with time zone when needed

The main rule is: keep internal time precise and consistent; make displayed time readable and appropriate for the user.

10. A Quick Timestamp Troubleshooting Checklist

When a converted timestamp looks wrong, check:

  • Is the number 10, 13, 16, or 19 digits long?
  • Is the unit seconds, milliseconds, microseconds, or nanoseconds?
  • Should the result be displayed in UTC or a local time zone?
  • Does the input date string include a time zone or offset?
  • Does the server automatically use its local time zone?
  • Does the API documentation define the date-time format clearly?
  • Does the database column automatically convert time zones?

For a quick manual check, paste the value into the Timestamp Converter and compare the UTC result with your local-time result.

Conclusion

A timestamp is conceptually simple: it is a number that measures the distance from a fixed starting point to a specific moment. Real-world usage becomes tricky because precision, time zones, formats, and platform defaults vary.

To avoid most problems, remember three rules: confirm whether the timestamp is in seconds or milliseconds, store and exchange time in UTC or with an explicit offset, and convert to local time only when displaying it to users. With those rules in place, timestamps become a reliable foundation for software systems, logs, APIs, analytics, and scheduling.