Java Code Examples for java.time.LocalDateTime#getHour()
The following examples show how to use
java.time.LocalDateTime#getHour() .
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 File: ZipUtils.java From Bytecoder with Apache License 2.0 | 6 votes |
/** * 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 2
Source File: AmodeusTimeConvert.java From amodeus with GNU General Public License v2.0 | 6 votes |
/** @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 File: AbstractTablist.java From FunnyGuilds with Apache License 2.0 | 6 votes |
@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 4
Source File: Greeter.java From tutorials with MIT License | 5 votes |
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 5
Source File: TimeUtil.java From game-server with MIT License | 5 votes |
public static long getDayOfMinute() { LocalDateTime localDateTime = getLocalDateTime(); int hour = localDateTime.getHour(); int minute = localDateTime.getMinute(); minute = hour * 60 + minute; return minute; }
Example 6
Source File: BotLogger.java From TelegramApi with MIT License | 5 votes |
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 7
Source File: ZipUtils.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
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 8
Source File: DataLabel.java From MeteoInfo with GNU Lesser General Public License v3.0 | 5 votes |
/** * 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 9
Source File: LogRoller.java From mdw with Apache License 2.0 | 5 votes |
@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 10
Source File: TimeStampMilliAccessor.java From dremio-oss with Apache License 2.0 | 5 votes |
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 11
Source File: PackedLocalDateTime.java From tablesaw with Apache License 2.0 | 5 votes |
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 12
Source File: TimeOfDay.java From SmartApplianceEnabler with GNU General Public License v2.0 | 4 votes |
public TimeOfDay(LocalDateTime dateTime) { hour = dateTime.getHour(); minute = dateTime.getMinute(); second = dateTime.getSecond(); }
Example 13
Source File: Timestamp.java From dragonwell8_jdk with GNU General Public License v2.0 | 3 votes |
/** * 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
Source File: Timestamp.java From jdk1.8-source-analysis with Apache License 2.0 | 3 votes |
/** * 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
Source File: Timestamp.java From JDKSourceCode1.8 with MIT License | 3 votes |
/** * 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
Source File: Timestamp.java From openjdk-8-source with GNU General Public License v2.0 | 3 votes |
/** * 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 File: Timestamp.java From Java8CN with Apache License 2.0 | 3 votes |
/** * 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
Source File: Timestamp.java From openjdk-8 with GNU General Public License v2.0 | 3 votes |
/** * 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 File: Timestamp.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 3 votes |
/** * 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
Source File: Timestamp.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 3 votes |
/** * 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()); }