I´m writing an application composed of a C++ process that acquires data and stores it in a Sqlite3 database, and a PHP Web application to analyze that data.
Some collected data generates DateTime
formats, that are stored on a INTEGER
type field on Sqlite3.
At the C++ side, the following piece of code is used to generate the timestamps (in milliseconds precision, as I´m dealing with a real time system):
int64_t convertTimePointToInt64(const std::chrono::time_point<std::chrono::system_clock> &time)
{
auto count = time.time_since_epoch();
auto value = std::chrono::duration_cast<std::chrono::milliseconds>(count);
return value.count();
}
std::chrono::time_point<std::chrono::system_clock> dt = std::chrono::system_clock::now();
auto valueToStore = convertTimePointToInt64(dt);
The valueToStore
is then INSERT´ed on Sqlite using SQL (INTEGER
type).
My problem is when I try to read it on the Web application. I´m using the following PHP code, where $t
is the database INTEGER value:
$micro = sprintf("%06d",($t - floor($t)) * 1000000);
$d = new \DateTime( date('Y-m-d H:i:s.'.$micro, $t) );
$a = $d->format("Y-m-d H:i:s.u");
I´m getting stange values (1031 in year, for example) that indicates the PHP logic is messy.
The C++ code is running very fine (I can store and retrive timestamps and convert it to/back to std::string
). I need to fix my PHP code to show the data correctly.
Help appreciated.