TimeUtils.java

  1. package com.renomad.minum.utils;

  2. import java.time.ZoneId;
  3. import java.time.ZonedDateTime;
  4. import java.time.format.DateTimeFormatter;
  5. import java.time.temporal.ChronoUnit;

  6. public final class TimeUtils {

  7.     private TimeUtils() {
  8.         // cannot construct
  9.     }

  10.     public static String getTimestampIsoInstant() {
  11.         ZonedDateTime now = ZonedDateTime.now(ZoneId.of("UTC"));
  12.         return getTimestampIsoInstantInner(now);
  13.     }

  14.     static String getTimestampIsoInstantInner(ZonedDateTime now) {
  15.         return now.truncatedTo(ChronoUnit.MICROS).format(DateTimeFormatter.ISO_INSTANT);
  16.     }
  17. }