Depending on which version of EOSIO you use, there are different options available for finding the current time. What are they?
2 Answers
Until eosio.cdt v1.6
You could use:
eosio::current_time()
now()
From eosio.cdt v1.6 onwards
You have to #include <eosio/system.hpp>
and then you can use:
eosio::current_time_point
eosio::current_block_time
-
1Where was this change mentioned, I don't see it in any release notes. Commented Apr 3, 2019 at 11:55
-
2I don't think they mentioned it directly. It was just something you had to find out for yourself. That is why I made a question and answered it, anticipating people having this problem. Commented Apr 3, 2019 at 21:13
-
1thank you. I wish they would bloody document stuff like this so poor sods like me don't spend all kinds of hours trying to figure out why something doesn't work. question: I see in the 1.6.1 version of the CDT, that
now()
is still defined: github.com/EOSIO/eosio.cdt/blob/master/libraries/eosiolib/… however, if I#include <eosio/system.hpp>
I still get the error "use of undeclared identifier 'now'; did you mean 'new'?" -- why is that and how do I fix it?– ekkisCommented Jun 18, 2019 at 23:39 -
1and if I look in libraries/eosiolib/system.hpp, I don't see either current_time_point or current_block_time (I need to know the return types)... how does this work? I see that including from eosiolib is deprecated and we must include from eosio, but I don't see any such directory!– ekkisCommented Jun 18, 2019 at 23:45
-
1and what the hell was wrong with providing
now()
anyway?? I'm so aggravated– ekkisCommented Jun 18, 2019 at 23:45
In older version we can only get the current block time with publish_time(). But now its available also in eosio::current_time_point eosio::current_block_time. Hope this helps you.