Java Code Examples for java.sql.Timestamp#toLocalDateTime()

The following examples show how to use java.sql.Timestamp#toLocalDateTime() . 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: RedoLog.java    From datacollector with Apache License 2.0 6 votes vote down vote up
public RedoLog(
    String path,
    BigDecimal thread,
    BigDecimal sequence,
    Timestamp firstTime,
    Timestamp nextTime,
    BigDecimal firstChange,
    BigDecimal nextChange,
    boolean dictionaryBegin,
    boolean dictionaryEnd
) {
  this(path,
      thread,
      sequence,
      firstTime.toLocalDateTime(),
      nextTime == null ? null : nextTime.toLocalDateTime(), firstChange, nextChange,
      dictionaryBegin,
      dictionaryEnd);
}
 
Example 2
Source File: Java8DatePropertyHandler.java    From oxygen with Apache License 2.0 6 votes vote down vote up
@Override
public Object cast(Class<?> type, Object value) {
  Timestamp timestamp = new Timestamp(((Date) value).getTime());
  if (type == Instant.class) {
    value = timestamp.toInstant();
  } else if (type == JapaneseDate.class) {
    value = JapaneseDate.from(timestamp.toLocalDateTime());
  } else if (type == LocalDateTime.class) {
    value = timestamp.toLocalDateTime();
  } else if (type == LocalDate.class) {
    value = timestamp.toLocalDateTime().toLocalDate();
  } else if (type == LocalTime.class) {
    value = timestamp.toLocalDateTime().toLocalTime();
  } else if (type == OffsetDateTime.class) {
    value = OffsetDateTime.ofInstant(timestamp.toInstant(), ZoneId.systemDefault());
  } else if (type == OffsetTime.class) {
    value = timestamp.toLocalDateTime().atOffset(OffsetDateTime.now().getOffset()).toOffsetTime();
  } else if (type == ZonedDateTime.class) {
    value = ZonedDateTime.ofInstant(timestamp.toInstant(), ZoneId.systemDefault());
  }
  return value;
}
 
Example 3
Source File: TimestampTests.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test42() throws Exception {
    Timestamp ts1 = Timestamp.valueOf("1961-08-30 00:00:00");
    LocalDateTime ldt = ts1.toLocalDateTime();
    Timestamp ts2 = Timestamp.valueOf(ldt);
    assertTrue(ts1.equals(ts2), "Error ts1 != ts2");
}
 
Example 4
Source File: LocalDateTimeConverter.java    From eds-starter6-jpa with Apache License 2.0 5 votes vote down vote up
@Override
public LocalDateTime convertToEntityAttribute(Timestamp value) {
	if (value != null) {
		return value.toLocalDateTime();
	}
	return null;
}
 
Example 5
Source File: TimestampTests.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test42() throws Exception {
    Timestamp ts1 = Timestamp.valueOf("1961-08-30 00:00:00");
    LocalDateTime ldt = ts1.toLocalDateTime();
    Timestamp ts2 = Timestamp.valueOf(ldt);
    assertTrue(ts1.equals(ts2), "Error ts1 != ts2");
}
 
Example 6
Source File: TimestampTests.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test42() throws Exception {
    Timestamp ts1 = Timestamp.valueOf("1961-08-30 00:00:00");
    LocalDateTime ldt = ts1.toLocalDateTime();
    Timestamp ts2 = Timestamp.valueOf(ldt);
    assertTrue(ts1.equals(ts2), "Error ts1 != ts2");
}
 
Example 7
Source File: LocalDateTimeMapper.java    From dropwizard-java8 with Apache License 2.0 5 votes vote down vote up
@Override
protected LocalDateTime extractByName(final ResultSet r, final String name) throws SQLException {
    final Timestamp timestamp = r.getTimestamp(name);
    if (timestamp == null) {
        return null;
    }
    return timestamp.toLocalDateTime();
}
 
Example 8
Source File: DbQueryConfiguration.java    From weasis-pacs-connector with Eclipse Public License 2.0 5 votes vote down vote up
private static LocalDateTime getLocalDateTimeFromTimeStamp(ResultSet resultSet, String field) throws SQLException {
    Timestamp timestamp = resultSet.getTimestamp(field);
    if (timestamp != null) {
        return timestamp.toLocalDateTime();
    }
    return null;
}
 
Example 9
Source File: TimestampTests.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test42() throws Exception {
    Timestamp ts1 = Timestamp.valueOf("1961-08-30 00:00:00");
    LocalDateTime ldt = ts1.toLocalDateTime();
    Timestamp ts2 = Timestamp.valueOf(ldt);
    assertTrue(ts1.equals(ts2), "Error ts1 != ts2");
}
 
Example 10
Source File: TimestampTests.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test42() throws Exception {
    Timestamp ts1 = Timestamp.valueOf("1961-08-30 00:00:00");
    LocalDateTime ldt = ts1.toLocalDateTime();
    Timestamp ts2 = Timestamp.valueOf(ldt);
    assertTrue(ts1.equals(ts2), "Error ts1 != ts2");
}
 
Example 11
Source File: TimestampTests.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test42() throws Exception {
    Timestamp ts1 = Timestamp.valueOf("1961-08-30 00:00:00");
    LocalDateTime ldt = ts1.toLocalDateTime();
    Timestamp ts2 = Timestamp.valueOf(ldt);
    assertTrue(ts1.equals(ts2), "Error ts1 != ts2");
}
 
Example 12
Source File: LocalDateTimeMapper.java    From dropwizard-java8 with Apache License 2.0 5 votes vote down vote up
@Override
protected LocalDateTime extractByIndex(final ResultSet r, final int index) throws SQLException {
    final Timestamp timestamp = r.getTimestamp(index);
    if (timestamp == null) {
        return null;
    }
    return timestamp.toLocalDateTime();
}
 
Example 13
Source File: TimestampTests.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test42() throws Exception {
    Timestamp ts1 = Timestamp.valueOf("1961-08-30 00:00:00");
    LocalDateTime ldt = ts1.toLocalDateTime();
    Timestamp ts2 = Timestamp.valueOf(ldt);
    assertTrue(ts1.equals(ts2), "Error ts1 != ts2");
}
 
Example 14
Source File: SQLExtractor.java    From morpheus-core with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public <V> V getValue(ResultSet rs, int colIndex) throws SQLException {
    final Timestamp timestamp = rs.getTimestamp(colIndex);
    return timestamp != null ? (V)timestamp.toLocalDateTime() : null;
}
 
Example 15
Source File: DateTimeConverter.java    From logging-log4j-audit with Apache License 2.0 4 votes vote down vote up
@Override
public LocalDateTime convertToEntityAttribute(Timestamp timestamp) {
    return timestamp == null ? null : timestamp.toLocalDateTime();
}
 
Example 16
Source File: PersistentLocalDateTime.java    From vics with MIT License 4 votes vote down vote up
@Override
public LocalDateTime convertToEntityAttribute(Timestamp value) {
    return value == null ? null : value.toLocalDateTime();
}
 
Example 17
Source File: LocalDateAttributeConverter.java    From spring-boot-oauth2-jwt with MIT License 4 votes vote down vote up
@Override
public LocalDateTime convertToEntityAttribute(Timestamp timestamp) {
	return (timestamp == null ? null : timestamp.toLocalDateTime());
}
 
Example 18
Source File: TimestampColumnMonthDayMapper.java    From jadira with Apache License 2.0 4 votes vote down vote up
@Override
public MonthDay fromNonNullValue(Timestamp value) {
	
	LocalDateTime ldt = value.toLocalDateTime();
    return MonthDay.of(ldt.getMonth(), ldt.getDayOfMonth());
}
 
Example 19
Source File: TimestampColumnLocalDateTimeMapper.java    From jadira with Apache License 2.0 4 votes vote down vote up
@Override
public LocalDateTime fromNonNullValue(Timestamp value) {
	
    return value.toLocalDateTime();
}
 
Example 20
Source File: DateTimeUtil.java    From ApplicationPower with Apache License 2.0 2 votes vote down vote up
/**
 * format TimeStamp to string
 *
 * @param time java.sql.Timestamp
 * @param fmt  String
 * @return String
 */
public static String timestampToString(Timestamp time, String fmt) {
    DateTimeFormatter dateTimeFormatter = createCacheFormatter(fmt);
    LocalDateTime dateTime = time.toLocalDateTime();
    return dateTimeFormatter.format(dateTime);
}