I am using PHP Client for InfluxDB - https://github.com/influxdata/influxdb-client-php
I am inserting points in my measurement along with current timestamp. For the timestamp, I am using as follows -
$time = new \DateTime();
$timezone=new\DateTimeZone('UTC');
$time->setTimestamp($unixTime)->setTimezone($timezone);
And then in then while inserting the point I am using -
->time($time->getTimestamp());
When I echo this variable, I get the correct timestamp, but when I am checkin values in the InfluxDB, all the dates are replaced by
1970-01-01T00:00:01.659452061Z
I even set the timezone to be UTC. I am not sure how to get the current timestamp into InfluxDB. Any help would be appreciated.
My Answer:
> $time = new \DateTime();
> $timezone = new \DateTimeZone('UTC');
> $time->setTimezone($timezone);
> $timestamp = $time->format('Y-m-d\TH:i:s.u\Z');
By setting the timezone to UTC and formatting the timestamp in the specified format, you can ensure that the timestamp is correctly written to InfluxDB without getting modified to `1970-01-01T00:00:01.659452061Z`.
Rate this post
4 of 5 based on 2656 votesComments