java.sql.Timestamp.toLocalDateTime()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(6.8k)|赞(0)|评价(0)|浏览(160)

本文整理了Java中java.sql.Timestamp.toLocalDateTime()方法的一些代码示例,展示了Timestamp.toLocalDateTime()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Timestamp.toLocalDateTime()方法的具体详情如下:
包路径:java.sql.Timestamp
类名称:Timestamp
方法名:toLocalDateTime

Timestamp.toLocalDateTime介绍

暂无

代码示例

代码示例来源:origin: requery/requery

@Override
  public LocalDateTime convertToMapped(Class<? extends LocalDateTime> type,
                     java.sql.Timestamp value) {
    if (value == null) {
      return null;
    }
    return value.toLocalDateTime();
  }
}

代码示例来源:origin: debezium/debezium

protected Object convertTimestampToLocalDateTime(Column column, Field fieldDefn, Object data) {
  if (data == null) {
    return null;
  }
  if (!(data instanceof Timestamp)) {
    return data;
  }
  final Timestamp timestamp = (Timestamp) data;
  return timestamp.toLocalDateTime();
}

代码示例来源:origin: speedment/speedment

@Override
public LocalDateTime toJavaType(Column column, Class<?> entityType, Timestamp value) {
  return value == null ? null : value.toLocalDateTime();
}

代码示例来源:origin: dropwizard/dropwizard

@Override
@Nullable
public LocalDateTime mapColumn(ResultSet r, String columnLabel, StatementContext ctx) throws SQLException {
  final Timestamp timestamp = r.getTimestamp(columnLabel);
  if (timestamp == null) {
    return null;
  }
  return timestamp.toLocalDateTime();
}

代码示例来源:origin: dropwizard/dropwizard

@Override
  @Nullable
  public LocalDateTime mapColumn(ResultSet r, int columnNumber, StatementContext ctx) throws SQLException {
    final Timestamp timestamp = r.getTimestamp(columnNumber);
    if (timestamp == null) {
      return null;
    }
    return timestamp.toLocalDateTime();
  }
}

代码示例来源:origin: dropwizard/dropwizard

@Override
  @Nullable
  public LocalDate mapColumn(ResultSet r, int columnNumber, StatementContext ctx) throws SQLException {
    final Timestamp timestamp = r.getTimestamp(columnNumber);
    if (timestamp == null) {
      return null;
    }
    return timestamp.toLocalDateTime().toLocalDate();
  }
}

代码示例来源:origin: dropwizard/dropwizard

@Override
@Nullable
public LocalDate mapColumn(ResultSet r, String columnLabel, StatementContext ctx) throws SQLException {
  final Timestamp timestamp = r.getTimestamp(columnLabel);
  if (timestamp == null) {
    return null;
  }
  return timestamp.toLocalDateTime().toLocalDate();
}

代码示例来源:origin: jdbi/jdbi

private static LocalDateTime getLocalDateTime(ResultSet r, int i) throws SQLException {
  Timestamp ts = r.getTimestamp(i);
  return ts == null ? null : ts.toLocalDateTime();
}

代码示例来源:origin: jdbi/jdbi

private static LocalDate getLocalDate(ResultSet r, int i) throws SQLException {
  Timestamp ts = r.getTimestamp(i);
  return ts == null ? null : ts.toLocalDateTime().toLocalDate();
}

代码示例来源:origin: stackoverflow.com

import java.time.LocalDateTime;
import javax.persistence.AttributeConverter;
import javax.persistence.Converter;

@Converter
public class LocalDateTimePersistenceConverter implements AttributeConverter<LocalDateTime, java.sql.Timestamp> {

 @Override
 public java.sql.Timestamp convertToDatabaseColumn(LocalDateTime entityValue) {
  if (entityValue != null) {
   return java.sql.Timestamp.valueOf(entityValue);
  }
  return null;
 }

 @Override
 public LocalDateTime convertToEntityAttribute(java.sql.Timestamp databaseValue) {
  if (databaseValue != null) {
   return databaseValue.toLocalDateTime();
  }
  return null;
 }
}

代码示例来源:origin: hibernate/hibernate-orm

@Override
  public LocalDateTime convertToEntityAttribute(Timestamp timestamp) {
    return timestamp == null ? null : timestamp.toLocalDateTime();
  }
}

代码示例来源:origin: apache/hive

@Override
public String toString() {
 if (timestampEmpty) {
  populateTimestamp();
 }
 if (timestamp.getNanos() > 0) {
  return timestamp.toString();
 }
 return timestamp.toLocalDateTime().format(DATE_TIME_FORMAT);
}

代码示例来源:origin: yu199195/Raincat

/**
 * 将数据库时间改成当前时区时间.
 * @param timestamp 时间
 * @return  time
 * @date 2018/5/9 18:25
 */
public static LocalDateTime toDefaultDateTime(final Timestamp timestamp) {
  return timestamp == null ? null : toDefaultDateTime(timestamp.toLocalDateTime());
}

代码示例来源:origin: debezium/debezium

protected Object convertTimestampToLocalDateTime(Column column, Field fieldDefn, Object data) {
    if (data == null && !fieldDefn.schema().isOptional()) {
      return null;
    }
    if (!(data instanceof Timestamp)) {
      return data;
    }

    return ((Timestamp)data).toLocalDateTime();
  }
}

代码示例来源:origin: jtablesaw/tablesaw

@Override
public DateTimeColumn appendObj(Object obj) {
  if (obj == null) {
    return appendMissing();
  }
  if (obj instanceof LocalDateTime) {
    return append((LocalDateTime) obj);
  }
  if (obj instanceof Timestamp ){
    Timestamp timestamp = (Timestamp) obj;
    return append(timestamp.toLocalDateTime());
  }
  throw new IllegalArgumentException("Cannot append " + obj.getClass().getName() + " to DateTimeColumn");
}

代码示例来源:origin: stackoverflow.com

return ((java.sql.Timestamp) date).toLocalDateTime();
else
  return Instant.ofEpochMilli(date.getTime()).atZone(zone).toLocalDateTime();

代码示例来源:origin: spring-projects/spring-framework

protected void verifyPerson(SpacePerson bean) {
  assertEquals("Bubba", bean.getLastName());
  assertEquals(22L, bean.getAge());
  assertEquals(new java.sql.Timestamp(1221222L).toLocalDateTime(), bean.getBirthDate());
  assertEquals(new BigDecimal("1234.56"), bean.getBalance());
}

代码示例来源:origin: spring-projects/spring-framework

@Test  // SPR-16483
public void useDefaultConversionService() throws SQLException {
  Timestamp timestamp = new Timestamp(0);
  SingleColumnRowMapper<LocalDateTime> rowMapper = SingleColumnRowMapper.newInstance(LocalDateTime.class);
  ResultSet resultSet = mock(ResultSet.class);
  ResultSetMetaData metaData = mock(ResultSetMetaData.class);
  given(metaData.getColumnCount()).willReturn(1);
  given(resultSet.getMetaData()).willReturn(metaData);
  given(resultSet.getObject(1, LocalDateTime.class))
      .willThrow(new SQLFeatureNotSupportedException());
  given(resultSet.getTimestamp(1)).willReturn(timestamp);
  LocalDateTime actualLocalDateTime = rowMapper.mapRow(resultSet, 1);
  assertEquals(timestamp.toLocalDateTime(), actualLocalDateTime);
}

代码示例来源:origin: spring-projects/spring-framework

@Test  // SPR-16483
public void useCustomConversionService() throws SQLException {
  Timestamp timestamp = new Timestamp(0);
  DefaultConversionService myConversionService = new DefaultConversionService();
  myConversionService.addConverter(Timestamp.class, MyLocalDateTime.class,
      source -> new MyLocalDateTime(source.toLocalDateTime()));
  SingleColumnRowMapper<MyLocalDateTime> rowMapper =
      SingleColumnRowMapper.newInstance(MyLocalDateTime.class, myConversionService);
  ResultSet resultSet = mock(ResultSet.class);
  ResultSetMetaData metaData = mock(ResultSetMetaData.class);
  given(metaData.getColumnCount()).willReturn(1);
  given(resultSet.getMetaData()).willReturn(metaData);
  given(resultSet.getObject(1, MyLocalDateTime.class))
      .willThrow(new SQLFeatureNotSupportedException());
  given(resultSet.getObject(1)).willReturn(timestamp);
  MyLocalDateTime actualMyLocalDateTime = rowMapper.mapRow(resultSet, 1);
  assertNotNull(actualMyLocalDateTime);
  assertEquals(timestamp.toLocalDateTime(), actualMyLocalDateTime.value);
}

代码示例来源:origin: apache/storm

int dateInt = (int) timestamp.toLocalDateTime().atOffset(ZoneOffset.UTC).toLocalDate().toEpochDay();
int localTimeInt = (int) (localTimestamp % DateTimeUtils.MILLIS_PER_DAY);
int currentTimeInt = (int) (currentTimestamp % DateTimeUtils.MILLIS_PER_DAY);

相关文章