1

In Solidty, you can use now keyword or block.timestamp to get the timestamp of the current block. This value, which is set by the block miner, can be used to work with time in your smart contract (which will treat 'now' as the time at which the miner says the code was executed).

The number returned is given in standard UNIX 'epoch' time, which is the UINT32 number of seconds since January 1, 1970 at 00:00:00 (midnight, start of day).

3

I did some research and discovered that UNIX 'epoch' time is in UTC, "Universal Time Code". Though technically UTC is not a time zone but GMT is, UTC converts directly to UTC, and can be easily converted to any local time zone. See here for more detail.

To confirm this, I used Remix to deploy and run a simple smart contract using Rinkeby, an Ethereum test network. My smart contract simply requests the current time by using `block.timestamp' and allows the value to be queried:

pragma solidity ^0.5.2;

contract NowContract {
    uint32 public nowValue = 0;

    constructor () public NowContract() {
        computeNow();
    }

    function computeNow() public {
        nowValue = uint32(block.timestamp);
    }
}

At right about 5 PM on 3/7/2019 in California (PDT), I called computeNow and then inspected nowValue. I got back the value 1552006848 which I then fed in to this site to convert it to a date. I got back:

03/08/2019 @ 1:00am (UTC)

It is easily verified that 3/7/2019 @5:00pm (PDT) is the same as 03/08/2019 @ 1:00am (UTC).

Moral of the story: As one would hope, when building blockchain applications that need to have awareness of the current date/time, you can be sure that no matter where your smart contract code runs, the result is always in UTC.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.