Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

How to Read Unix Timestamps, Convert Them, and Measure Time

Unix timestamps represent instants relative to 1970-01-01 UTC, but units, precision, time conversion, and platform range all need careful handling.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A Unix timestamp identifies an instant relative to 1970-01-01 00:00:00 UTC. It is usually expressed in seconds for POSIX-style interfaces, but APIs also use milliseconds, and the number alone does not tell you its unit or precision. Treat timestamps as instants, convert them explicitly for display, and use a monotonic clock—not calendar time—for measuring durations.

What is a Unix timestamp?

The Unix epoch is 1970-01-01 00:00:00 UTC. Python defines it as the point returned by time.gmtime(0) and states that it is the same on all platforms. A Unix timestamp is a numeric representation of an instant relative to that epoch; POSIX-style interfaces commonly express it in seconds.

As an Amazon Associate I earn from qualifying purchases.

Those seconds are a convention, not a count of every physical SI second since 1970. POSIX time excludes leap seconds. The Open Group explains that ignoring leap seconds supports a compatible way to compute time differences, and Linux documentation describes POSIX time as an approximation of elapsed time that ignores leap seconds. The Open Group rationale and the Linux time(2) manual describe this convention.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Are timestamps in seconds or milliseconds?

There is no single unit across programming interfaces. For example, Python’s time.time() returns a floating-point number of seconds since the epoch, while JavaScript’s Date represents an integral number of milliseconds since it. Python also cautions that the actual clock precision may be lower than the decimal digits suggest. JavaScript documents its representation in the Date reference.

Interface Representation Conversion consideration
Python time.time() Floating-point seconds since the epoch Decimal appearance does not guarantee that level of clock precision; round deliberately when converting.
JavaScript Date Integral milliseconds since the epoch Convert seconds to milliseconds by multiplying by 1,000; convert milliseconds to seconds by dividing by 1,000.

At an API or storage boundary, make the unit explicit—for example, name a field created_at_ms or document that created_at is seconds. Do not infer units only from a number’s digit count: ranges overlap, and a plausible-looking value can be misinterpreted by a factor of 1,000.

How do you convert a timestamp to a date safely?

Keep the timestamp as an instant until presentation. Convert it to UTC or to a specifically chosen local timezone for display; do not treat a host-local date/time string as a portable timestamp. Local-time rules depend on timezone data and can change, including daylight-saving transitions.

Rank #2
Sale
The Unix Programming Environment (Prentice-Hall Software Series)
  • The Unix Programming Environment (Prentice-Hall Software Series)
  • Product Type: ABIS_BOOK
  • Pearson

Python

  • Use time.gmtime(seconds) when you need UTC calendar components.
  • Use time.localtime(seconds) when you intentionally need the host’s local calendar components.
  • For a timestamp returned by JavaScript in milliseconds, divide by 1,000 before passing it to Python APIs expecting seconds.

Python documents the distinction between UTC and local conversion and notes that local-time behavior is delegated to the platform’s C library, whose timezone rules can change. See the Python time documentation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

JavaScript

  • Construct a Date using milliseconds. If your input is seconds, multiply by 1,000 first.
  • Use UTC-oriented methods when you need UTC components. Basic component accessors such as local date and hour accessors use the host’s local timezone.
  • When sending values to another system, document whether the serialized number is seconds or milliseconds rather than relying on the receiver to guess.

When converting between seconds and milliseconds, account for rounding and precision as well as the unit. A fractional number of seconds may not map cleanly to an integral millisecond, and a displayed decimal does not prove that the source clock measured time at that resolution.

Which clock should you use for elapsed time?

Use a monotonic clock for durations, timeouts, and performance intervals. Wall-clock time can be adjusted, so subtracting two calendar-clock readings can produce a misleading duration. Python’s time.monotonic() cannot go backwards due to system clock updates; its reference point is undefined, so only differences between readings are meaningful.

  1. Read the monotonic clock immediately before the operation.
  2. Read it again afterward or when checking a timeout.
  3. Subtract the earlier reading from the later one and interpret the difference in the documented unit.

Use an epoch timestamp when you need to identify or exchange a calendar instant. Do not store or display a monotonic reading as though it were a date.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What is the Year 2038 problem?

Some systems historically represented epoch seconds in a signed 32-bit integer. That representation cannot cover timestamps beyond 2038, creating the Year 2038 problem for software that still relies on that limit. It does not mean that every modern computer will fail in 2038: the actual range depends on the operating-system ABI, runtime, libraries, and persisted data formats.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The Linux time(2) manual recommends an ABI with a time_t wider than 32 bits for applications intended to run past 2038. Check the complete path that handles a timestamp—not just the application language—including database columns, message formats, file formats, system calls, and any systems that read the data later.

Quick Recap

SaleBestseller No. 2
The Unix Programming Environment (Prentice-Hall Software Series)
The Unix Programming Environment (Prentice-Hall Software Series)
The Unix Programming Environment (Prentice-Hall Software Series); Product Type: ABIS_BOOK; Pearson
$70.65
SaleBestseller No. 3
SaleBestseller No. 4

Practical checks for timestamp interfaces

  • Specify the unit: seconds, milliseconds, or another unit must be clear in names, schemas, and API documentation.
  • Specify the time basis: distinguish an epoch-based instant from a local date/time string.
  • Check precision: floating-point seconds may display more decimal places than the clock can reliably measure; conversions can also round.
  • Use the right clock: epoch time for calendar instants, monotonic time for elapsed intervals.
  • Verify range end to end: check runtime and platform limits as well as storage and interchange formats, especially for dates after 2038.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.