EOS.IO Asked by chris de jong on August 20, 2021
I’m trying to print an ISO timestamp with second accuracy.
#include <chrono>
#include <ctime>
time_t current_time = current_time_point().sec_since_epoch() * 1000;
char* charTime = std::put_time( std::localtime(¤t_time), "%FT%T%z" );
print(charTime);
I’ve tried several combinations. I keep getting complaints about the namespace:
error: no member named 'localtime' in namespace 'std'
What is the correct way of doing this using cdt 1.6.1?
eosio.cdt doesn't support time library in its libc, so you cannot use time related functions. eoscc
, a customized version of eosio.cdt, supports it. (I'm a writer of that)
You can check it from here.
std::strftime
instead of std::put_time
. put_time needs stream.std::time_t
accepts seconds, so do not multiply time_point::sec_since_epoch()
with 1000.std::gmtime
instead of std::localtime
. localtime requires timezone.char buffer[32];
time_t current_time = current_time_point().sec_since_epoch();
std::strftime(buffer, sizeof(buffer), "%FT%TZ", std::gmtime(¤t_time));
print(buffer);
Answered by conr2d on August 20, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP