Skip to content

Checking your reading list…

Retry

Stay curious. Build better.

Appearance

Choose how BestHub looks on this device.

Changes apply immediately.

Search articles

Open Discover with these filters

Suggested searches

Blockchain 2 min read

How to Retrieve and Convert Blockchain Block Timestamps in Java

This guide explains that blockchain block creation times are stored as Unix timestamps in seconds, describes the Unix time concept, shows how to convert timestamps in Java from milliseconds to seconds and back, and provides a concrete Ethereum example using Web3.js to fetch a block’s timestamp.

Block Timestamp Retrieval

Both Bitcoin and Ethereum blocks store their creation time as a Unix timestamp measured in seconds, not milliseconds, so using the raw value without conversion will produce incorrect dates.

Unix Timestamp Overview

A Unix timestamp (POSIX time) counts the total seconds elapsed since 00:00:00 UTC on 1 January 1970.

Conversion in Java

In Java, new Date().getTime() or System.currentTimeMillis() returns the current time in milliseconds. To obtain a Unix‑second timestamp, divide by 1000, e.g., System.currentTimeMillis() / 1000. Conversely, a Unix timestamp can be turned into a Java Date with new java.util.Date(unixTimestamp * 1000).

Example with Ethereum

Ethereum block data often includes a field like:

timestamp: Number - the unix timestamp for when the block was collated.

Using Web3.js you can fetch the block number and its timestamp:

web3.eth.getTransaction("0x5da2844afb6826d4baed6ad7e8b536c00cbc921ac147773ad056f29f2e7c1762").blockNumber
1920050
web3.eth.getBlock(1920050).timestamp
1469021581
About this article

For questions about attribution, corrections or content rights, please contactadmin@besthub.devand we will review it promptly.

timestampUnix

Discussion 0

Questions, practical examples and thoughtful responses.

Open full discussion