Java Instant Format toInfluxDBTimeFormat(final Instant time)

Here you can find the source of toInfluxDBTimeFormat(final Instant time)

Description

convert a unix epoch time to timestamp used by influxdb.

License

Open Source License

Parameter

Parameter Description
time timestamp to use, in unix epoch time

Return

influxdb compatible date-tome string

Declaration

public static String toInfluxDBTimeFormat(final Instant time) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;

public class Main {
    /**//from ww  w  .  ja v  a  2s .  c o  m
     * convert a unix epoch time to timestamp used by influxdb.
     * this can then be used in query expressions against influxdb's time column like so:
     * influxDB.query(new Query("SELECT * FROM some_measurement WHERE time >= '"
     *                          + toInfluxDBTimeFormat(timeStart) + "'", some_database))
     * influxdb time format example: 2016-10-31T06:52:20.020Z
     *
     * @param time timestamp to use, in unix epoch time
     * @return influxdb compatible date-tome string
     */
    public static String toInfluxDBTimeFormat(final Instant time) {
        return DateTimeFormatter.ISO_INSTANT.format(ZonedDateTime.ofInstant(time, ZoneId.of("UTC").normalized()));
    }
}

Related

  1. formatHttpDate(Instant instant)
  2. formatInstant(TemporalAccessor instant)
  3. formatIso8601Date(Instant date)
  4. formatTimeLocal(Instant instant)
  5. parseInstant(String dateString, DateTimeFormatter formatter)