31 releases (17 major breaking)

new 19.0.0 Mar 26, 2023
18.0.0 Mar 5, 2023
17.0.0 Feb 26, 2023
16.0.0 Feb 19, 2023
2.0.0-alpha.5 Mar 24, 2020

#344 in Magic Beans

Download history 1226/week @ 2022-12-06 1071/week @ 2022-12-13 979/week @ 2022-12-20 550/week @ 2022-12-27 241/week @ 2023-01-03 866/week @ 2023-01-10 843/week @ 2023-01-17 1370/week @ 2023-01-24 1300/week @ 2023-01-31 438/week @ 2023-02-07 913/week @ 2023-02-14 1151/week @ 2023-02-21 688/week @ 2023-02-28 945/week @ 2023-03-07 844/week @ 2023-03-14 646/week @ 2023-03-21

3,510 downloads per month
Used in 37 crates (28 directly)


35K SLoC

Timestamp Module

The Timestamp module provides functionality to get and set the on-chain time.


The Timestamp module allows the validators to set and validate a timestamp with each block.

It uses inherents for timestamp data, which is provided by the block author and validated/verified by other validators. The timestamp can be set only once per block and must be set each block. There could be a constraint on how much time must pass before setting the new timestamp.

NOTE: The Timestamp module is the recommended way to query the on-chain time instead of using an approach based on block numbers. The block number based time measurement can cause issues because of cumulative calculation errors and hence should be avoided.


Dispatchable Functions

  • set - Sets the current time.

Public functions

  • get - Gets the current time for the current block. If this function is called prior to setting the timestamp, it will return the timestamp of the previous block.

Config Getters

  • MinimumPeriod - Gets the minimum (and advised) period between blocks for the chain.


The following example shows how to use the Timestamp module in your custom module to query the current timestamp.


Import the Timestamp module into your custom module and derive the module configuration trait from the timestamp trait.

Get current timestamp

use pallet_timestamp::{self as timestamp};

pub mod pallet {
    use super::*;
    use frame_support::pallet_prelude::*;
    use frame_system::pallet_prelude::*;

    pub struct Pallet<T>(_);

    pub trait Config: frame_system::Config + timestamp::Config {}

    impl<T: Config> Pallet<T> {
        pub fn get_time(origin: OriginFor<T>) -> DispatchResult {
            let _sender = ensure_signed(origin)?;
            let _now = <timestamp::Pallet<T>>::get();

Example from the FRAME

The Session module uses the Timestamp module for session management.

License: Apache-2.0


~759K SLoC