public static Instant fromMillisOrIso8601(String time, String fieldName) {
    try {
      return Instant.ofEpochMilli(Long.parseLong(time));
    } catch (NumberFormatException nfe) {
      // TODO: copied from PluginConfigurationProcessor, find a way to share better
      try {
        DateTimeFormatter formatter =
            new DateTimeFormatterBuilder()
                .append(DateTimeFormatter.ISO_DATE_TIME)
                .optionalStart()
                .appendOffset("+HHmm", "+0000")
                .optionalEnd()
                .toFormatter();
        return formatter.parse(time, Instant::from);
      } catch (DateTimeParseException dtpe) {
        throw new IllegalArgumentException(
            fieldName
                + " must be a number of milliseconds since epoch or an ISO 8601 formatted date");
      }
    }
  }
Parses a time string into Instant. The string must be time in milliseconds since unix epoch or
an iso8601 datetime.

@param time in milliseconds since epoch or iso8601 format
@param fieldName name of field being parsed (for error messaging)
@return Instant value of parsed time
jib-cli/src/main/java/com/google/cloud/tools/jib/cli/Instants.java