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

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

A Unix timestamp identifies an instant by counting from 1970-01-01 00:00:00 UTC. The number does not contain a time zone, and the word “timestamp” does not tell you whether its unit is seconds, milliseconds, or something else. Check the API or data contract first; then convert and display the instant using the intended time zone.

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, positive values are later instants, and negative values are earlier ones. It is an elapsed-time count, not a local date or a time-zone label. POSIX timestamps exclude leap seconds. Python’s time documentation describes the epoch and this POSIX behavior.

The count alone does not determine how a person should see the instant on a calendar. A display zone converts the same instant into local date and clock components. For example, one instant may be shown as different local times in two regions without changing its timestamp.

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

Seconds, milliseconds, and other units

“Timestamp” is not a unit specification. Python’s POSIX timestamp conversions use seconds, while JavaScript’s Date values and Date.now() use milliseconds since the UTC epoch. Other systems may use microseconds or nanoseconds. Consult the API documentation or the field’s schema rather than assuming a unit. Python datetime documentation and MDN’s Date.now() reference document these language-specific conventions.

Digit count can help with a quick plausibility check: contemporary timestamps are often around ten digits in seconds or thirteen in milliseconds. That is only a rough inference, not a standard; the number of digits changes with the date and representation.

Convert milliseconds to whole seconds in JavaScript

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

Use Math.floor() when you need the number of complete elapsed seconds. Rounding can report a second before that full second has elapsed. MDN documents Date.now() as returning integer milliseconds; browser privacy settings may reduce clock precision. MDN: Date.now()

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

Convert seconds to an aware UTC datetime in Python

from datetime import datetime, timezone

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

Passing timezone.utc makes the resulting datetime aware and explicitly UTC. Python recommends this form for UTC conversion. Python datetime documentation

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Keep the instant separate from its display time zone

When displaying an instant in another zone, convert it to that zone; do not alter the underlying timestamp. JavaScript Date represents a UTC-anchored millisecond count, while ordinary date component methods use the device’s local time zone. Use UTC getters when you specifically need UTC components. MDN: Date

For date-time text exchanged over the internet, include a zone designator such as Z for UTC or a numeric offset. RFC 3339 shows that 18:50:00-04:00 is the same instant as 22:50:00Z; the numeric offset is local time minus UTC. A string such as 2026-10-07 09:00 has no offset or zone, so a recipient cannot reliably infer the intended instant. RFC 3339

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
$77.35
SaleBestseller No. 3
SaleBestseller No. 4

Common timestamp mistakes and how to avoid them

  • Passing seconds to a millisecond API, or the reverse. A seconds value passed to JavaScript’s millisecond-based Date represents an instant near the beginning of 1970. Reading milliseconds as seconds can produce an out-of-range value. Verify the unit at the interface and convert deliberately.
  • Treating a naive Python datetime as UTC. Python treats a naive datetime’s timestamp() conversion as local time. If the value means UTC, use an aware UTC datetime; otherwise results can depend on the machine’s local zone. Python datetime documentation
  • Changing the timestamp to change the display zone. Keep the instant fixed and convert it for display. In JavaScript, local component methods and UTC getters intentionally produce components for different zones. MDN: Date
  • Exchanging unqualified local times. Include Z or a numeric offset in Internet date-time text so systems can determine the instant. RFC 3339
  • Assuming every day is exactly 86,400 POSIX seconds in a leap-second-aware sense. POSIX counts exclude leap seconds. RFC 3339 permits a textual second value of 60 for an announced leap second, but that does not mean every programming API can represent it. Python’s datetime does not support leap seconds. Python time documentation Python datetime documentation RFC 3339
  • Using a wall clock to measure elapsed duration. System clock adjustments can make Date.now() move non-monotonically. 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: Performance.now()
  • Assuming conversions have unlimited range. Python platform conversions may fail outside ranges supported by the underlying C library. JavaScript Date becomes invalid outside its specified range of ±8,640,000,000,000,000 milliseconds (±100,000,000 days). This is a JavaScript API limit, not a universal Unix timestamp limit. Python datetime documentation MDN: Date

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.