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

The following examples show how to use java.time.LocalDateTime#getSecond() . 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: DagManifesFileScanner.java    From tez with Apache License 2.0 6 votes vote down vote up
private boolean loadMore() throws IOException {
  LocalDateTime now = manifestLogger.getNow();
  LocalDate today = now.toLocalDate();
  String todayDir = manifestLogger.getDirForDate(today);
  loadNewFiles(todayDir);
  while (newFiles.isEmpty()) {
    if (now.getHour() * 3600 + now.getMinute() * 60 + now.getSecond() < syncTime) {
      // We are in the delay window for today, do not advance date if we are moving from
      // yesterday.
      if (scanDir.equals(manifestLogger.getDirForDate(today.minusDays(1)))) {
        return false;
      }
    }
    String nextDir = manifestLogger.getNextDirectory(scanDir);
    if (nextDir == null) {
      return false;
    }
    scanDir = nextDir;
    offsets = new HashMap<>();
    retryCount = new HashMap<>();
    loadNewFiles(todayDir);
  }
  return true;
}
 
Example 2
Source File: LocalDateTimeSerializer.java    From jackson-modules-java8 with Apache License 2.0 6 votes vote down vote up
private final void _serializeAsArrayContents(LocalDateTime value, JsonGenerator g,
        SerializerProvider provider) throws IOException
{
    g.writeNumber(value.getYear());
    g.writeNumber(value.getMonthValue());
    g.writeNumber(value.getDayOfMonth());
    g.writeNumber(value.getHour());
    g.writeNumber(value.getMinute());
    final int secs = value.getSecond();
    final int nanos = value.getNano();
    if ((secs > 0) || (nanos > 0)) {
        g.writeNumber(secs);
        if (nanos > 0) {
            if (useNanoseconds(provider)) {
                g.writeNumber(nanos);
            } else {
                g.writeNumber(value.get(ChronoField.MILLI_OF_SECOND));
            }
        }
    }
}
 
Example 3
Source File: AbstractTablist.java    From FunnyGuilds with 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 4
Source File: ZipUtils.java    From Bytecoder with 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 5
Source File: ZipUtils.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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 6
Source File: ExprDateParsed.java    From skUtilities with GNU General Public License v3.0 5 votes vote down vote up
@Override
@Nullable
protected Date[] get(Event e) {
  String s = id.getSingle(e);
  try {
    String ddf = new SimpleDateFormat().toPattern();
    if (format != null) ddf = format.getSingle(e);
    LocalDateTime ldt = LocalDateTime.parse(s, DateTimeFormatter.ofPattern(ddf));
    return new Date[]{new Date((ldt.toEpochSecond(ZoneOffset.ofTotalSeconds(ldt.getSecond())) + ldt.getSecond()) * 1000)};
  } catch (Exception x) {
    skUtilities.prSysE(x.getMessage(), getClass().getSimpleName(), x);
  }
  return null;
}
 
Example 7
Source File: TimeStampMilliAccessor.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
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 8
Source File: BotLogger.java    From TelegramApi with 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 9
Source File: PackedLocalDateTime.java    From tablesaw with 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 10
Source File: PackedLocalDateTime.java    From tablesaw with 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 11
Source File: Java8TestLocalDateTime.java    From javase with MIT License 5 votes vote down vote up
public void testLocalDateTime(){

     // Get the current date and time
     LocalDateTime currentTime = LocalDateTime.now();
     System.out.println("Current DateTime: " + currentTime);
	
     LocalDate date1 = currentTime.toLocalDate();
     System.out.println("date1: " + date1);
	
     Month month = currentTime.getMonth();
     int day = currentTime.getDayOfMonth();
     int seconds = currentTime.getSecond();
	
     System.out.println("Month: " + month +"day: " + day +"seconds: " + seconds);
	
     LocalDateTime date2 = currentTime.withDayOfMonth(10).withYear(2012);
     System.out.println("date2: " + date2);
	
     //12 december 2014
     LocalDate date3 = LocalDate.of(2014, Month.DECEMBER, 12);
     System.out.println("date3: " + date3);
	
     //22 hour 15 minutes
     LocalTime date4 = LocalTime.of(22, 15);
     System.out.println("date4: " + date4);
	
     //parse a string
     LocalTime date5 = LocalTime.parse("20:15:30");
     System.out.println("date5: " + date5);
  }
 
Example 12
Source File: TimePrintMillis.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
public TimePrintMillis(LocalDateTime time) {
  super(time.getHour(), time.getMinute(), time.getSecond());
  millisOfSecond = time.get(ChronoField.MILLI_OF_SECOND);
}
 
Example 13
Source File: Timestamp.java    From jdk8u_jdk with GNU General Public License v2.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 14
Source File: Timestamp.java    From openjdk-jdk8u-backup with GNU General Public License v2.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 15
Source File: Timestamp.java    From Java8CN with 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 16
Source File: Timestamp.java    From hottub with GNU General Public License v2.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 17
Source File: Timestamp.java    From TencentKona-8 with GNU General Public License v2.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 18
Source File: Timestamp.java    From openjdk-jdk9 with GNU General Public License v2.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 19
Source File: Timestamp.java    From dragonwell8_jdk with GNU General Public License v2.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
Source File: Timestamp.java    From jdk1.8-source-analysis with 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());
}