Unix Timestamp Converter

Convert a Unix epoch timestamp into a readable date, or turn a date back into a timestamp. Works in seconds or milliseconds, UTC and local time.

Timestamp to date

UTC
 
ISO 8601
 
Local time
 

Date to timestamp

Unix seconds
 
Unix milliseconds
 

Working with Unix time

Unix time counts seconds since the epoch, 1 January 1970 UTC. Because it carries no timezone, it is the standard way systems exchange a point in time. Ethereum block headers use it too: the timestamp field is Unix seconds, so you can paste a block timestamp above to see when that block was produced.

Watch the digit count: a 10-digit number is almost certainly seconds, a 13-digit number is milliseconds. Pick the matching unit so the date comes out right.

Block timestamps since the merge

Proof of work made block times a probability distribution; proof of stake makes them a schedule. Slots are exactly 12 seconds long and every block belongs to a slot, so consecutive timestamps differ by 12 seconds, or by a multiple of 12 when a proposer misses its turn and the slot goes empty. That is what makes time to block number a calculation rather than a search.

Two rules constrain the value. It must be strictly greater than the parent's timestamp, so the sequence never goes backwards, and the proposer chooses it, so it can sit slightly ahead of real time. In practice it is accurate to within a slot. That is fine for charting, ordering and daily aggregation, and it is not fine for anything where a few seconds of proposer discretion is worth money.

// The Beacon Chain genesis, and the slot clock everything hangs off.
const GENESIS = 1606824023;  // 2020-12-01 12:00:23 UTC
const SLOT    = 12;          // seconds

const slotAt = (unixSeconds) => Math.floor((unixSeconds - GENESIS) / SLOT);

// Blocks lag slots slightly because missed slots produce no block,
// so this is an upper bound you then walk down.
slotAt(1735689600); // 2025-01-01 00:00:00 UTC

Finding the block at a point in time

The naive approach is a binary search over the whole chain, which costs about 25 calls to eth_getBlockByNumber and is what most snippets on the internet do. Because the slot clock is fixed you can do far better: estimate, measure the error, correct, and repeat. It converges in two or three calls.

import { WebSocketProvider } from "ethers";

// Inside a BLAZED.sh container or script this is the co-located node.
const provider = new WebSocketProvider("ws://eth:8545");

async function blockAt(targetSeconds) {
  let block = await provider.getBlock("latest");

  // Each pass uses the real 12s cadence to jump most of the remaining gap.
  for (let i = 0; i < 6; i++) {
    const drift = block.timestamp - targetSeconds;
    if (Math.abs(drift) <= 12) break;
    const guess = block.number - Math.round(drift / 12);
    block = await provider.getBlock(Math.max(guess, 1));
  }

  // Walk the last slot or two to land on the first block at or after target.
  while (block.timestamp > targetSeconds) {
    block = await provider.getBlock(block.number - 1);
  }
  return block;
}

Every iteration is a round trip, which is why this pattern feels different depending on where the node is. Against a public gateway each pass costs 50 to 500 milliseconds and counts against a rate limit, so backfilling a year of daily boundaries turns into a job you have to babysit. On a co-located node the same loop runs over a Unix socket in single digit milliseconds, and the calls draw predictable per-request credits instead of an opaque compute unit. The eth_getBlockByNumber reference documents the response shape, and the timestamps in it arrive as hex quantities, which the hex converter turns back into the seconds you can paste above.

Frequently asked questions

What is a Unix timestamp?

A Unix timestamp is the number of seconds elapsed since 00:00:00 UTC on 1 January 1970, the Unix epoch. It is a timezone-independent way to represent a moment in time.

Seconds or milliseconds?

Unix timestamps are traditionally in seconds (10 digits today). JavaScript's Date uses milliseconds (13 digits). This tool lets you pick either.

How do Ethereum block timestamps work?

Each Ethereum block header carries a timestamp field in Unix seconds, set by the validator that proposed the block. Paste it here to read it as a date.

How do I find the block at a given time?

Since the merge, slots are exactly 12 seconds apart, so you can estimate a block number by dividing the time difference by 12 and correcting for missed slots. The section below has the arithmetic and a short refinement loop that converges in two or three calls.

Can a block timestamp be wrong or go backwards?

It cannot go backwards: consensus rules require each block's timestamp to be greater than its parent's. It can drift forwards a little, because the proposer sets it, so treat it as accurate to within a slot rather than as a precise clock.

Is block.timestamp safe to use in a contract?

For deadlines measured in minutes or longer, yes. For anything where a few seconds of proposer discretion changes the outcome, such as short expiry windows or randomness, no. A proposer can nudge it, and that nudge is exactly the edge an attacker needs.

Does this send my data anywhere?

No. The conversion runs entirely in your browser with the built-in Date API. Nothing leaves your machine.

From a timestamp to the block itself

Converting a block timestamp usually means you are trying to find what happened around that moment. Against a remote provider that search costs a round trip per guess, and the guesses add up. On a co-located node the same walk runs over a Unix socket.

eth_getBlockByNumber reference