[Solved]How to set epoch in influxdb-java?

Hello.
I would like to return epoch time(ms) long in the java query instead of the default string rfc3339 but I don’t see a way on the java client even through OkHttpClient since HttpUrl is not used. I am using the latest influxdb-java 2.9.

Any pointers highly appreciated. Thank you!

The return epoch time is determined by the query to the Influx API. You’ll have to forgive me for now being overly familiar with the java client, but I know that to change the epoch in the API, you would have to write something this:
http://127.0.0.1:8086/query?pretty=true --data-urlencode "db=telegraf" --data-urlencode "q=SELECT * FROM cpu limit 1" --data-urlencode "epoch=ms" {

Try adding the epoch option to your query and see if that helps.

Hi Katy,

I’ll just put the answer here for posterity:
query(final Query query, TimeUnit.MILLISECONDS);
will return a Double which needs to be cast.

Thanks!

1 Like