Is the block.timestamp value in Solidity seconds or milliseconds?

  • I'm looking to use block.timestamp in one of my contracts and I want to know whether the block.timestamp is seconds like in Python or milliseconds like in Java or some other value?

    Also, is it safe to use block.timestamp to check if 30 days is past since the last updated time or something like that?

    The `blocks.timestamp` is a Unix time stamp. So, it has the complete information about the date, hours, minutes, and seconds (in UTC) when the block was created.

    I thank you for your response. I very much appreciate it and for providing more details and clarifications.

  • From the Solidity documentation (here and here):

    ... timestamp of the current block in seconds since the epoch

    For your other question:

    Also, is it safe to use block.timestamp to check if 30 days is past since the last updated time or something like that?

    Your question isn't completely clear, but assuming you're questioning the validity of a timestamp over a given period of time, then this previous answer should cover it: Is block.timestamp safe for longer time periods?

    Thanks for pointing out the documentation. I some how missed it it is seconds. Let's say I set a timestamp value: lastUpdated in a previous block. In a future block, I check if the lastUpdated is past 30 days or not to do some action. Would this be a safe check? Assuming that the difference in time difference is reasonable(order of days) and not too close?

    30 days will work fine. It should be accurate to within a half hour or so at worst

License under CC-BY-SA with attribution


Content dated before 7/24/2021 11:53 AM