Java DateTimeFormatter fromInfluxDBTimeFormat(final String timestamp)

Here you can find the source of fromInfluxDBTimeFormat(final String timestamp)

Description

from Influx DB Time Format

License

Open Source License

Declaration

public static Instant fromInfluxDBTimeFormat(final String timestamp) 

Method Source Code

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

import java.time.Instant;

import java.time.format.DateTimeFormatter;

public class Main {
    public static Instant fromInfluxDBTimeFormat(final String timestamp) {
        return Instant.from(DateTimeFormatter.ISO_INSTANT.parse(timestamp));
    }//from  ww w.  j  a  va 2s .  co  m

    public static Instant fromInfluxDBTimeFormat(final Object timestamp) throws Exception {
        if (timestamp == null)
            throw new Exception("Cannot convert null to instant timestamp");

        if (timestamp instanceof String)
            return fromInfluxDBTimeFormat((String) timestamp);

        if (timestamp instanceof Double) {
            Double millis = (Double) timestamp / 1000000.0;
            Double nanos = (Double) timestamp - (millis * 1000000.0);
            return Instant.ofEpochMilli(millis.longValue()).plusNanos(nanos.longValue());
        }

        throw new Exception("Cannot convert nonstring object to instant : " + timestamp.getClass().getName());
    }
}

Related

  1. formatISOUTCDateTime(long timestamp)
  2. formatNow(String format)
  3. formatTime(long milliSeconds)
  4. formatTimestamp(long timestamp)
  5. formatTimestap(final long timestap)
  6. fromString(String dateString, DateTimeFormatter formatter)
  7. getDateFormat()
  8. getDateFormat(final Locale LOCALE)
  9. getDateFromFormat(String dtStr)