public static Timestamp getTimestamp(NanoTime nt, ZoneId targetZone, boolean legacyConversion) {
    int julianDay = nt.getJulianDay();
    long nanosOfDay = nt.getTimeOfDayNanos();

    long remainder = nanosOfDay;
    julianDay += remainder / NANOS_PER_DAY;
    remainder %= NANOS_PER_DAY;
    if (remainder < 0) {
      remainder += NANOS_PER_DAY;
      julianDay--;
    }

    JulianDate jDateTime = JulianDate.of((double) julianDay);
    LocalDateTime localDateTime;
    int leapYearDateAdjustment = 0;
    try {
      localDateTime = jDateTime.toLocalDateTime();
    } catch (DateTimeException e) {
      if (e.getMessage().contains(TimestampTZUtil.NOT_LEAP_YEAR) && legacyConversion) {
        leapYearDateAdjustment = 2;
        localDateTime = jDateTime.add(leapYearDateAdjustment).toLocalDateTime();
      } else {
        throw e;
      }
    }
    Calendar calendar = getGMTCalendar();
    calendar.set(Calendar.YEAR, localDateTime.getYear());
    calendar.set(Calendar.MONTH, localDateTime.getMonth().getValue() - 1); //java calendar index starting at 1.
    calendar.set(Calendar.DAY_OF_MONTH, localDateTime.getDayOfMonth());

    int hour = (int) (remainder / (NANOS_PER_HOUR));
    remainder = remainder % (NANOS_PER_HOUR);
    int minutes = (int) (remainder / (NANOS_PER_MINUTE));
    remainder = remainder % (NANOS_PER_MINUTE);
    int seconds = (int) (remainder / (NANOS_PER_SECOND));
    long nanos = remainder % NANOS_PER_SECOND;

    calendar.set(Calendar.HOUR_OF_DAY, hour);
    calendar.set(Calendar.MINUTE, minutes);
    calendar.set(Calendar.SECOND, seconds);

    Timestamp ts = Timestamp.ofEpochMilli(calendar.getTimeInMillis(), (int) nanos);
    ts = TimestampTZUtil.convertTimestampToZone(ts, ZoneOffset.UTC, targetZone, legacyConversion)
        .minusDays(leapYearDateAdjustment);

    return ts;
  }
Converts a nanotime representation in UTC, to a timestamp in the specified timezone.

@param legacyConversion when true the conversion to the target timezone is done with legacy (backwards compatible)
method.
ql/src/java/org/apache/hadoop/hive/ql/io/parquet/timestamp/NanoTimeUtils.java