I want to convert a time_point variable to a string using eos studio. I need to insert a time_point variable in a string in order to creare the object of my smart contract.
1 Answer
below is my code:
struct TimePoint_micro_sec {
int64_t count;
[[nodiscard]] std::string ToString() const;
};
std::string TimePoint_micro_sec::ToString() const {
const uint64_t seconds = count / 1'000'000ULL;
const uint64_t milliseconds = (count % 1'000'000ULL) / 1'000ULL;
const std::string padded_ms = std::to_string(milliseconds + 1'000ULL).substr(1);
const auto ptime = boost::posix_time::from_time_t(time_t(seconds));
return boost::posix_time::to_iso_extended_string(ptime) + "." + padded_ms;
}