DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowHalloween 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 PC×
Skip to content
World desk4 min

Unix Timestamps Explained: Seconds, Milliseconds, Time Zones and Common Mistakes

Unix timestamps identify instants from the UTC epoch, but APIs differ on units and date-time handling. Learn how to convert seconds and milliseconds safely and avoid time-zone mistakes.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A Unix timestamp is a number that identifies an instant relative to 1970-01-01 00:00:00 UTC. The number itself is not a local date or time zone. Before converting it, check the unit: Python’s POSIX timestamp methods use seconds, while JavaScript’s Date and Date.now() use milliseconds. A unit mix-up can turn a current date into a date near 1970—or an invalid value.

What a Unix timestamp represents

The conventional Unix or POSIX epoch is 1970-01-01 00:00:00 UTC. A POSIX timestamp counts seconds from that reference: 0 is the epoch, a positive number is later, and a negative number is earlier. POSIX timestamps exclude leap seconds. Python’s time documentation describes the epoch and this POSIX convention.

As an Amazon Associate I earn from qualifying purchases.

A timestamp identifies an instant; it does not encode a time zone. A time zone is needed when that instant is rendered as civil calendar time, such as “9 a.m. in New York.” The same instant can appear as different local clock readings in different zones.

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

Seconds or milliseconds? Check the API contract

The word “timestamp” does not specify a unit. Consult the API documentation or the data schema rather than guessing from the number. As a rough sanity check, contemporary seconds values often have about ten digits and contemporary milliseconds values about thirteen, but digit count is not a guarantee.

API Unit and use
Python POSIX timestamp conversions Seconds; use an aware UTC datetime when converting to a date.
JavaScript Date and Date.now() Milliseconds since the UTC epoch.

These conventions are language- and API-specific, not a universal rule for every field called a timestamp. Python’s datetime documentation documents seconds-based timestamp conversions, while MDN’s Date.now() reference specifies integer milliseconds.

JavaScript: convert milliseconds to whole seconds

const milliseconds = Date.now();
const seconds = Math.floor(milliseconds / 1000);
const date = new Date(milliseconds); // Date expects milliseconds

Use Math.floor() when converting to integer seconds. Rounding can move the value forward to a second that has not fully elapsed.

Python: convert seconds to an aware UTC datetime

from datetime import datetime, timezone

seconds = 1_700_000_000
instant = datetime.fromtimestamp(seconds, tz=timezone.utc)
round_trip = instant.timestamp()

Python recommends using datetime.fromtimestamp(timestamp, tz=timezone.utc) for an aware UTC result. The Python datetime documentation also explains the different behavior of naive datetimes.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Sale
The Unix Programming Environment (Prentice-Hall Software Series)
  • The Unix Programming Environment (Prentice-Hall Software Series)
  • Product Type: ABIS_BOOK
  • Pearson

How time zones affect display—and how to exchange dates safely

Convert an instant to the intended display zone; do not change its timestamp to make it look like a local time. In JavaScript, a Date stores a UTC-anchored millisecond count, while ordinary date-component methods use the device’s local zone. Use UTC getters when you need UTC components. MDN’s Date reference describes the timestamp model and available date methods.

When sending a date-time as text, include Z for UTC or a numeric offset. For example, RFC 3339’s 18:50:00-04:00 denotes the same instant as 22:50:00Z; the offset is local time minus UTC. A string such as 2026-10-07 09:00 has no zone or offset, so a recipient cannot reliably determine its intended instant. RFC 3339 discusses qualified date-times and the interoperability problems of unqualified local times.

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

Common timestamp mistakes

Passing seconds to a millisecond API, or the reverse

JavaScript’s Date expects milliseconds. Passing it a seconds value therefore points near the start of 1970. Interpreting milliseconds as seconds can instead produce a value beyond an API’s supported range. Confirm the unit at the point where data enters your program, and convert once at a clearly defined boundary.

Treating a naive Python datetime as UTC

A naive Python datetime has no time-zone information. Calling timestamp() on it treats it as local time, so a value intended by its creator to mean UTC can produce different results on machines configured for different zones. Use an aware datetime with the real time zone—UTC when the value means UTC—instead. Python documents this local-time behavior and recommends aware UTC conversions.

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.

Confusing local display with the instant

Changing the zone used to display a timestamp should change the calendar components, not the underlying instant. In JavaScript, local date methods and UTC date methods answer different display questions; neither changes the stored millisecond timestamp.

Assuming every day contains exactly 86,400 POSIX seconds

POSIX timestamps exclude leap seconds, so they are not a leap-second-inclusive count of every physical second. RFC 3339 permits the textual seconds value 60 for an announced leap second, but that does not mean every programming API can represent it. Python’s datetime module does not support leap seconds. Python’s time documentation, RFC 3339 and Python’s datetime documentation describe these distinct behaviors.

Using a wall clock to measure elapsed time

Date.now() reports wall-clock time, which can move non-monotonically if the system clock is adjusted. For elapsed performance timing in JavaScript, MDN recommends Performance.now(), which is monotonic and relative to a performance time origin rather than the Unix epoch. MDN’s Performance.now() reference explains the distinction.

Assuming conversions have unlimited range or precision

Conversion support depends on the API and platform. Python timestamp conversions may fail outside ranges supported by the platform C library. JavaScript Date supports timestamps only within ±8,640,000,000,000,000 milliseconds (±100,000,000 days); beyond that range, the date is invalid. MDN notes that browsers may also reduce the precision of Date.now() values. These are API limits, not universal limits on the idea of a Unix timestamp. Python’s datetime documentation, MDN’s Date reference and MDN’s Date.now() reference cover these constraints.

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

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

A quick checklist for interpreting a timestamp

  • Find the field’s documented unit: seconds, milliseconds, or another unit.
  • Confirm the epoch or reference point used by the producing API.
  • Determine whether the value represents an instant or is actually an unqualified civil date-time.
  • When converting text to an instant, require UTC or an explicit numeric offset.
  • Use aware date-time values and an explicit display zone.
  • For elapsed duration, choose a monotonic clock rather than a wall-clock timestamp.
  • Check range, precision, and leap-second behavior where edge cases matter.

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 *

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

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
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

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.