> ## Documentation Index
> Fetch the complete documentation index at: https://solana.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> This page is part of the Solana developer documentation at https://solana.com/developers/docs. Append `.md` to any docs URL, or send `Accept: text/markdown`, to get the page as Markdown.
> Index of all pages: https://solana.com/llms.txt. Per-section indexes such as https://solana.com/developers/docs/payments/llms.txt are smaller; prefer them when working on one task.
> Coding agents: install the official Solana skill for current APIs and conventions with `npx skills add https://github.com/solana-foundation/solana-dev-skill` (also served at https://solana.com/SKILL.md).
> Code in the cookbook and task pages comes from tested example files. Prefer it over writing API calls from memory.

# getBlockTime

> Returns the estimated production time for a block.

<Info>
  **Source**

  [`get_block_time`](https://github.com/anza-xyz/agave/blob/v4.3.2/rpc/src/rpc.rs#L1615)
</Info>

<Info>
  Each validator reports their UTC time to the ledger on a regular interval by
  intermittently adding a timestamp to a Vote for a particular block. A
  requested block's time is calculated from the stake-weighted mean of the Vote
  timestamps in a set of recent blocks recorded on the ledger.
</Info>

<RequestExample>
  ```bash cURL
  curl https://api.devnet.solana.com -s -X POST \
    -H "Content-Type: application/json" \
    -d '
    {
      "jsonrpc": "2.0",
      "id": 1,
      "method": "getBlockTime",
      "params": [
        377268280
      ]
    }
  '
  ```

  ```ts Kit
  import { createSolanaRpc } from "@solana/kit";

  const rpc_url = "https://api.devnet.solana.com";
  const rpc = createSolanaRpc(rpc_url);

  let slotNumber = BigInt(377268280);
  let blockTime = await rpc.getBlockTime(slotNumber).send();

  console.log("Block time:", blockTime);
  ```

  ```ts web3.js
  import { Connection, clusterApiUrl } from "@solana/web3.js";

  const connection = new Connection(clusterApiUrl("devnet"), "confirmed");

  let slotNumber = 377268280;
  let blockTime = await connection.getBlockTime(slotNumber);

  console.log("Block time:", blockTime);
  ```

  ```rs Rust
  use anyhow::Result;
  use solana_client::nonblocking::rpc_client::RpcClient;
  use solana_commitment_config::CommitmentConfig;

  #[tokio::main]
  async fn main() -> Result<()> {
      let client = RpcClient::new_with_commitment(
          String::from("https://api.devnet.solana.com"),
          CommitmentConfig::confirmed(),
      );

      let slot_number = 377268280;

      let block_time = client.get_block_time(slot_number).await?;

      println!("Blocks time: {:?}", block_time);

      Ok(())
  }
  ```
</RequestExample>

<ResponseExample>
  ```json available
  {
    "jsonrpc": "2.0",
    "result": 1574721591,
    "id": 1
  }
  ```

  ```json title="unknown time"
  {
    "jsonrpc": "2.0",
    "result": null,
    "id": 1
  }
  ```

  ```json unavailable
  {
    "jsonrpc": "2.0",
    "error": {
      "code": -32004,
      "message": "Block not available for slot 150"
    },
    "id": 1
  }
  ```
</ResponseExample>

## Parameters

<ParamField body="slot number" type="u64" required>
  Slot number to query, as a u64 integer.
</ParamField>

## Result

<ResponseField name="result" type="i64" post={["available"]}>
  Estimated production time, as Unix timestamp (seconds since the Unix epoch)
</ResponseField>

<ResponseField name="result" type="null" post={["unknown time"]}>
  Returned when the block is available but no block time has been recorded.
</ResponseField>

<ResponseField name="result" type="object" post={["unavailable"]}>
  Error object
</ResponseField>
