Java Code Examples for java.time.LocalDateTime#getHour()

The following examples show how to use java.time.LocalDateTime#getHour() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: FunnyGuilds   File: AbstractTablist.java    License: Apache License 2.0 6 votes vote down vote up
@Deprecated
protected String putHeaderFooterVars(String text) {
    String formatted = text;

    LocalDateTime time = LocalDateTime.now();
    int hour = time.getHour();
    int minute = time.getMinute();
    int second = time.getSecond();

    formatted = StringUtils.replace(formatted, "{HOUR}", ChatUtils.appendDigit(hour));
    formatted = StringUtils.replace(formatted, "{MINUTE}", ChatUtils.appendDigit(minute));
    formatted = StringUtils.replace(formatted, "{SECOND}", ChatUtils.appendDigit(second));
    formatted = ChatUtils.colored(formatted);

    return formatted;
}
 
Example 2
/** @param epochSecond in Unix Epoch Time [seconds]
 * @return the time in the AMoDeus framework as an integer for the {@link LocalDateTime}
 * @param localDateTime and the simulation date @param simDate */
private int ldtToAmodeus(LocalDateTime localDateTime, LocalDate localDate, Long epochSecond) {
    int day = localDateTime.getDayOfYear() - localDate.getDayOfYear();
    int amodeusTime = day * 3600 * 24 //
            + localDateTime.getHour() * 3600//
            + localDateTime.getMinute() * 60 //
            + localDateTime.getSecond();
    if (amodeusTime < 0) {
        System.err.println("amodeus time is smaller than zero...");
        if (Objects.nonNull(epochSecond))
            System.err.println("unxTime:     " + epochSecond);
        System.err.println("ldt:         " + localDateTime.toString());
        System.err.println("simDate:     " + localDate.toString());
        System.err.println("amodeustime: " + amodeusTime);
    }
    GlobalAssert.that(amodeusTime >= 0);
    return amodeusTime;
}
 
Example 3
Source Project: Bytecoder   File: ZipUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Converts Java time to DOS time.
 */
private static long javaToDosTime(long time) {
    Instant instant = Instant.ofEpochMilli(time);
    LocalDateTime ldt = LocalDateTime.ofInstant(
            instant, ZoneId.systemDefault());
    int year = ldt.getYear() - 1980;
    if (year < 0) {
        return (1 << 21) | (1 << 16);
    }
    return (year << 25 |
        ldt.getMonthValue() << 21 |
        ldt.getDayOfMonth() << 16 |
        ldt.getHour() << 11 |
        ldt.getMinute() << 5 |
        ldt.getSecond() >> 1) & 0xffffffffL;
}
 
Example 4
Source Project: tablesaw   File: PackedLocalDateTime.java    License: Apache License 2.0 5 votes vote down vote up
public static long getMillisecondOfDay(long packedLocalDateTime) {
  LocalDateTime localDateTime = PackedLocalDateTime.asLocalDateTime(packedLocalDateTime);
  if (localDateTime == null) {
    throw new IllegalArgumentException("Cannot get millisecond of day for missing value");
  }
  long total = (long) localDateTime.get(ChronoField.MILLI_OF_SECOND);
  total += localDateTime.getSecond() * 1000;
  total += localDateTime.getMinute() * 60 * 1000;
  total += localDateTime.getHour() * 60 * 60 * 1000;
  return total;
}
 
Example 5
private Timestamp getTimestamp(int index, TimeZone tz) {
  if (ac.isNull(index)) {
    return null;
  }

  // The Arrow datetime values are already in UTC, so adjust to the timezone of the calendar passed in to
  // ensure the reported value is correct according to the JDBC spec.
  final LocalDateTime date = LocalDateTime.ofInstant(Instant.ofEpochMilli(ac.get(index)), tz.toZoneId());
  return new Timestamp(date.getYear() - 1900, date.getMonthValue() - 1, date.getDayOfMonth(),
    date.getHour(), date.getMinute(), date.getSecond(), date.getNano());
}
 
Example 6
Source Project: mdw   File: LogRoller.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    LocalDateTime now = LocalDateTime.now();
    // if I'm at 11 pm, it could mean the switch FROM Daylight Saving has occurred
    if (now.getHour() == 23) {
        // reschedule for midnight
        start();
        return;
    }

    if (files != null) {
        LocalDate today = LocalDate.now();
        logger.info("LogRoller executing at " + new Date());
        for (String file : files) {
            try {
                Files.deleteIfExists(toPath(file, today.minusDays(retain + 1)));
                Path path = new File(file).toPath();
                Files.copy(path, toPath(file, today.minusDays(1)), REPLACE_EXISTING);
                Files.write(path, new byte[0], StandardOpenOption.TRUNCATE_EXISTING);
            }
            catch (IOException ex) {
                logger.error(ex.getMessage(), ex);
            }
        }
    }

    // if I just ran at 1 am, it could mean the switch TO Daylight Saving has occurred
    // (adjust prior to next cycle)
    if (now.getHour() == 1) {
        start();
    }
}
 
Example 7
/**
 * Set time
 *
 * @param value Time
 */
public void setTime(LocalDateTime value) {
    _time = value;
    _year = value.getYear();
    _month = (short) value.getMonthValue();
    _day = (short) value.getDayOfMonth();
    _hour = (short) value.getHour();
}
 
Example 8
public static long javaToDosTime(long time) {
    Instant instant = Instant.ofEpochMilli(time);
    LocalDateTime ldt = LocalDateTime.ofInstant(
            instant, ZoneId.systemDefault());
    int year = ldt.getYear() - 1980;
    if (year < 0) {
        return (1 << 21) | (1 << 16);
    }
    return (year << 25 |
        ldt.getMonthValue() << 21 |
        ldt.getDayOfMonth() << 16 |
        ldt.getHour() << 11 |
        ldt.getMinute() << 5 |
        ldt.getSecond() >> 1) & 0xffffffffL;
}
 
Example 9
Source Project: tutorials   File: Greeter.java    License: MIT License 5 votes vote down vote up
public String greet(LocalDateTime localDateTime) {

        String name = greetingConfig.getProperty(USER_NAME);
        int hourOfDay = localDateTime.getHour();

        if (hourOfDay >= 5 && hourOfDay < 12) {
            return String.format("Hello %s, %s", name, greetingConfig.get(MORNING_MESSAGE));
        } else if (hourOfDay >= 12 && hourOfDay < 17) {
            return String.format("Hello %s, %s", name, greetingConfig.get(AFTERNOON_MESSAGE));
        } else if (hourOfDay >= 17 && hourOfDay < 20) {
            return String.format("Hello %s, %s", name, greetingConfig.get(EVENING_MESSAGE));
        } else {
            return String.format("Hello %s, %s", name, greetingConfig.get(NIGHT_MESSAGE));
        }
    }
 
Example 10
Source Project: TelegramApi   File: BotLogger.java    License: MIT License 5 votes vote down vote up
private static String dateFormatterForLogs(@NotNull LocalDateTime dateTime) {
    String dateString = "[";
    dateString += dateTime.getDayOfMonth() + "_";
    dateString += dateTime.getMonthValue() + "_";
    dateString += dateTime.getYear() + "_";
    dateString += dateTime.getHour() + ":";
    dateString += dateTime.getMinute() + ":";
    dateString += dateTime.getSecond();
    dateString += "] ";
    return dateString;
}
 
Example 11
Source Project: game-server   File: TimeUtil.java    License: MIT License 5 votes vote down vote up
public static long getDayOfMinute() {
    LocalDateTime localDateTime = getLocalDateTime();
    int hour = localDateTime.getHour();
    int minute = localDateTime.getMinute();
    minute = hour * 60 + minute;
    return minute;
}
 
Example 12
public TimeOfDay(LocalDateTime dateTime) {
    hour = dateTime.getHour();
    minute = dateTime.getMinute();
    second = dateTime.getSecond();
}
 
Example 13
/**
 * Obtains an instance of {@code Timestamp} from a {@code LocalDateTime}
 * object, with the same year, month, day of month, hours, minutes,
 * seconds and nanos date-time value as the provided {@code LocalDateTime}.
 * <p>
 * The provided {@code LocalDateTime} is interpreted as the local
 * date-time in the local time zone.
 *
 * @param dateTime a {@code LocalDateTime} to convert
 * @return a {@code Timestamp} object
 * @exception NullPointerException if {@code dateTime} is null.
 * @since 1.8
 */
@SuppressWarnings("deprecation")
public static Timestamp valueOf(LocalDateTime dateTime) {
    return new Timestamp(dateTime.getYear() - 1900,
                         dateTime.getMonthValue() - 1,
                         dateTime.getDayOfMonth(),
                         dateTime.getHour(),
                         dateTime.getMinute(),
                         dateTime.getSecond(),
                         dateTime.getNano());
}
 
Example 14
/**
 * Obtains an instance of {@code Timestamp} from a {@code LocalDateTime}
 * object, with the same year, month, day of month, hours, minutes,
 * seconds and nanos date-time value as the provided {@code LocalDateTime}.
 * <p>
 * The provided {@code LocalDateTime} is interpreted as the local
 * date-time in the local time zone.
 *
 * @param dateTime a {@code LocalDateTime} to convert
 * @return a {@code Timestamp} object
 * @exception NullPointerException if {@code dateTime} is null.
 * @since 1.8
 */
@SuppressWarnings("deprecation")
public static Timestamp valueOf(LocalDateTime dateTime) {
    return new Timestamp(dateTime.getYear() - 1900,
                         dateTime.getMonthValue() - 1,
                         dateTime.getDayOfMonth(),
                         dateTime.getHour(),
                         dateTime.getMinute(),
                         dateTime.getSecond(),
                         dateTime.getNano());
}
 
Example 15
/**
 * Obtains an instance of {@code Timestamp} from a {@code LocalDateTime}
 * object, with the same year, month, day of month, hours, minutes,
 * seconds and nanos date-time value as the provided {@code LocalDateTime}.
 * <p>
 * The provided {@code LocalDateTime} is interpreted as the local
 * date-time in the local time zone.
 *
 * @param dateTime a {@code LocalDateTime} to convert
 * @return a {@code Timestamp} object
 * @exception NullPointerException if {@code dateTime} is null.
 * @since 1.8
 */
@SuppressWarnings("deprecation")
public static Timestamp valueOf(LocalDateTime dateTime) {
    return new Timestamp(dateTime.getYear() - 1900,
                         dateTime.getMonthValue() - 1,
                         dateTime.getDayOfMonth(),
                         dateTime.getHour(),
                         dateTime.getMinute(),
                         dateTime.getSecond(),
                         dateTime.getNano());
}
 
Example 16
/**
 * Obtains an instance of {@code Timestamp} from a {@code LocalDateTime}
 * object, with the same year, month, day of month, hours, minutes,
 * seconds and nanos date-time value as the provided {@code LocalDateTime}.
 * <p>
 * The provided {@code LocalDateTime} is interpreted as the local
 * date-time in the local time zone.
 *
 * @param dateTime a {@code LocalDateTime} to convert
 * @return a {@code Timestamp} object
 * @exception NullPointerException if {@code dateTime} is null.
 * @since 1.8
 */
@SuppressWarnings("deprecation")
public static Timestamp valueOf(LocalDateTime dateTime) {
    return new Timestamp(dateTime.getYear() - 1900,
                         dateTime.getMonthValue() - 1,
                         dateTime.getDayOfMonth(),
                         dateTime.getHour(),
                         dateTime.getMinute(),
                         dateTime.getSecond(),
                         dateTime.getNano());
}
 
Example 17
Source Project: JDKSourceCode1.8   File: Timestamp.java    License: MIT License 3 votes vote down vote up
/**
 * Obtains an instance of {@code Timestamp} from a {@code LocalDateTime}
 * object, with the same year, month, day of month, hours, minutes,
 * seconds and nanos date-time value as the provided {@code LocalDateTime}.
 * <p>
 * The provided {@code LocalDateTime} is interpreted as the local
 * date-time in the local time zone.
 *
 * @param dateTime a {@code LocalDateTime} to convert
 * @return a {@code Timestamp} object
 * @exception NullPointerException if {@code dateTime} is null.
 * @since 1.8
 */
@SuppressWarnings("deprecation")
public static Timestamp valueOf(LocalDateTime dateTime) {
    return new Timestamp(dateTime.getYear() - 1900,
                         dateTime.getMonthValue() - 1,
                         dateTime.getDayOfMonth(),
                         dateTime.getHour(),
                         dateTime.getMinute(),
                         dateTime.getSecond(),
                         dateTime.getNano());
}
 
Example 18
/**
 * Obtains an instance of {@code Timestamp} from a {@code LocalDateTime}
 * object, with the same year, month, day of month, hours, minutes,
 * seconds and nanos date-time value as the provided {@code LocalDateTime}.
 * <p>
 * The provided {@code LocalDateTime} is interpreted as the local
 * date-time in the local time zone.
 *
 * @param dateTime a {@code LocalDateTime} to convert
 * @return a {@code Timestamp} object
 * @exception NullPointerException if {@code dateTime} is null.
 * @since 1.8
 */
@SuppressWarnings("deprecation")
public static Timestamp valueOf(LocalDateTime dateTime) {
    return new Timestamp(dateTime.getYear() - 1900,
                         dateTime.getMonthValue() - 1,
                         dateTime.getDayOfMonth(),
                         dateTime.getHour(),
                         dateTime.getMinute(),
                         dateTime.getSecond(),
                         dateTime.getNano());
}
 
Example 19
Source Project: Java8CN   File: Timestamp.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * Obtains an instance of {@code Timestamp} from a {@code LocalDateTime}
 * object, with the same year, month, day of month, hours, minutes,
 * seconds and nanos date-time value as the provided {@code LocalDateTime}.
 * <p>
 * The provided {@code LocalDateTime} is interpreted as the local
 * date-time in the local time zone.
 *
 * @param dateTime a {@code LocalDateTime} to convert
 * @return a {@code Timestamp} object
 * @exception NullPointerException if {@code dateTime} is null.
 * @since 1.8
 */
@SuppressWarnings("deprecation")
public static Timestamp valueOf(LocalDateTime dateTime) {
    return new Timestamp(dateTime.getYear() - 1900,
                         dateTime.getMonthValue() - 1,
                         dateTime.getDayOfMonth(),
                         dateTime.getHour(),
                         dateTime.getMinute(),
                         dateTime.getSecond(),
                         dateTime.getNano());
}
 
Example 20
/**
 * Obtains an instance of {@code Timestamp} from a {@code LocalDateTime}
 * object, with the same year, month, day of month, hours, minutes,
 * seconds and nanos date-time value as the provided {@code LocalDateTime}.
 * <p>
 * The provided {@code LocalDateTime} is interpreted as the local
 * date-time in the local time zone.
 *
 * @param dateTime a {@code LocalDateTime} to convert
 * @return a {@code Timestamp} object
 * @exception NullPointerException if {@code dateTime} is null.
 * @since 1.8
 */
@SuppressWarnings("deprecation")
public static Timestamp valueOf(LocalDateTime dateTime) {
    return new Timestamp(dateTime.getYear() - 1900,
                         dateTime.getMonthValue() - 1,
                         dateTime.getDayOfMonth(),
                         dateTime.getHour(),
                         dateTime.getMinute(),
                         dateTime.getSecond(),
                         dateTime.getNano());
}