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

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

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

Timestamp.toInstant介绍

暂无

代码示例

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

@Override
public Instant convert(Object val) throws ConverterException
{
  Timestamp ts = (Timestamp) val;
  return ts.toInstant();
}

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

private static Instant getInstant(ResultSet r, int i) throws SQLException {
  Timestamp ts = r.getTimestamp(i);
  return ts == null ? null : ts.toInstant();
}

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

@Override
@Nullable
public Instant mapColumn(ResultSet r, int columnNumber, StatementContext ctx) throws SQLException {
  final Timestamp timestamp = calendar.isPresent() ?
      r.getTimestamp(columnNumber, cloneCalendar()) :
      r.getTimestamp(columnNumber);
  return timestamp == null ? null : timestamp.toInstant();
}

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

@Override
@Nullable
public Instant mapColumn(ResultSet r, String columnLabel, StatementContext ctx) throws SQLException {
  final Timestamp timestamp = calendar.isPresent() ?
      r.getTimestamp(columnLabel, cloneCalendar()) :
      r.getTimestamp(columnLabel);
  return timestamp == null ? null : timestamp.toInstant();
}

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

private static ZonedDateTime getZonedDateTime(ResultSet r, int i) throws SQLException {
  Timestamp ts = r.getTimestamp(i);
  return ts == null ? null : ZonedDateTime.ofInstant(ts.toInstant(), ZoneId.systemDefault());
}

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

@Override
  public ZonedDateTime convertToMapped(Class<? extends ZonedDateTime> type, Timestamp value) {
    if (value == null) {
      return null;
    }
    Instant instant = value.toInstant();
    return ZonedDateTime.ofInstant(instant, ZoneOffset.systemDefault());
  }
}

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

private static OffsetDateTime getOffsetDateTime(ResultSet r, int i) throws SQLException {
  Timestamp ts = r.getTimestamp(i);
  return ts == null ? null : OffsetDateTime.ofInstant(ts.toInstant(), ZoneId.systemDefault());
}

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

/**
 * Get the ISO 8601 formatted representation of the given {@link java.sql.Timestamp}, which contains a date and time but
 * has no timezone information.
 * 
 * @param timestamp the JDBC timestamp value
 * @param zoneId the timezone identifier or offset where the timestamp is defined
 * @param adjuster the optional component that adjusts the local date value before obtaining the epoch day; may be null if no
 * adjustment is necessary
 * @return the ISO 8601 formatted string
 */
public static String toIsoString(java.sql.Timestamp timestamp, ZoneId zoneId, TemporalAdjuster adjuster) {
  Instant instant = timestamp.toInstant();
  if (adjuster != null) {
    instant = instant.with(adjuster);
  }
  ZonedDateTime zdt = instant.atZone(zoneId);
  return zdt.format(FORMATTER);
}

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

/**
 * Get the ISO 8601 formatted representation of the given {@link java.sql.Timestamp}, which contains a date and time but
 * has no timezone information.
 * 
 * @param timestamp the JDBC timestamp value; may not be null
 * @param zoneId the timezone identifier or offset where the timestamp is defined
 * @param adjuster the optional component that adjusts the local date value before obtaining the epoch day; may be null if no
 * adjustment is necessary
 * @return the ISO 8601 formatted string
 */
public static String toIsoString(java.sql.Timestamp timestamp, ZoneId zoneId, TemporalAdjuster adjuster) {
  ZonedDateTime zdt = timestamp.toInstant().atZone(zoneId);
  if (adjuster != null) {
    zdt = zdt.with(adjuster);
  }
  return zdt.format(FORMATTER);
}

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

return ZonedDateTime.ofInstant( ts.toInstant(), ZoneId.systemDefault() );

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

return LocalDateTime.ofInstant( ts.toInstant(), ZoneId.systemDefault() );

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

return ts.toInstant();

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

/**
 * Converts a string object for an object type of {@link Timestamp}.
 * If the column definition allows null and default value is 0000-00-00 00:00:00, we need return null,
 * else 0000-00-00 00:00:00 will be replaced with 1970-01-01 00:00:00;
 *
 * @param column the column definition describing the {@code data} value; never null
 * @param value the string object to be converted into a {@link Timestamp} type;
 * @return the converted value;
 */
private Object convertToTimestamp(Column column, String value) {
  final boolean matches = EPOCH_EQUIVALENT_TIMESTAMP.matcher(value).matches() || "0".equals(value) || EPOCH_TIMESTAMP.equals(value);
  if (matches) {
    if (column.isOptional()) {
      return null;
    }
    return Timestamp.from(Instant.EPOCH);
  }
  return Timestamp.valueOf(value).toInstant().atZone(ZoneId.systemDefault());
}

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

@Override
  public OffsetDateTime convertToMapped(Class<? extends OffsetDateTime> type, Timestamp value) {
    if (value == null) {
      return null;
    }
    return OffsetDateTime.ofInstant(value.toInstant(), ZoneOffset.systemDefault());
  }
}

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

@Override
public <X> LocalDate wrap(X value, WrapperOptions options) {
  if ( value == null ) {
    return null;
  }
  if ( LocalDate.class.isInstance( value ) ) {
    return (LocalDate) value;
  }
  if ( Timestamp.class.isInstance( value ) ) {
    final Timestamp ts = (Timestamp) value;
    return LocalDateTime.ofInstant( ts.toInstant(), ZoneId.systemDefault() ).toLocalDate();
  }
  if ( Long.class.isInstance( value ) ) {
    final Instant instant = Instant.ofEpochMilli( (Long) value );
    return LocalDateTime.ofInstant( instant, ZoneId.systemDefault() ).toLocalDate();
  }
  if ( Calendar.class.isInstance( value ) ) {
    final Calendar calendar = (Calendar) value;
    return LocalDateTime.ofInstant( calendar.toInstant(), calendar.getTimeZone().toZoneId() ).toLocalDate();
  }
  if ( Date.class.isInstance( value ) ) {
    if ( java.sql.Date.class.isInstance( value ) ) {
      return ((java.sql.Date) value).toLocalDate();
    }
    else {
      return Instant.ofEpochMilli( ((Date) value).getTime() ).atZone( ZoneId.systemDefault() ).toLocalDate();
    }
  }
  throw unknownWrap( value.getClass() );
}

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

return LocalDateTime.ofInstant( ts.toInstant(), ZoneId.systemDefault() ).toLocalTime();

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

return OffsetDateTime.ofInstant( ts.toInstant(), ZoneId.systemDefault() );

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

return OffsetTime.ofInstant( ts.toInstant(), ZoneId.systemDefault() );

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

@Override
  public IdCreateTime map(ResultSet rs, StatementContext ctx) throws SQLException {
    return new IdCreateTime(
        rs.getLong("id"),
        rs.getTimestamp("created_on").toInstant().atOffset(ZoneOffset.UTC));
  }
}

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

/**
 * Map a commit LSN to a point in time when the commit happened.
 *
 * @param lsn - LSN of the commit
 * @return time when the commit was recorded into the database log
 * @throws SQLException
 */
public Instant timestampOfLsn(Lsn lsn) throws SQLException {
  final String query = LSN_TO_TIMESTAMP;
  if (lsn.getBinary() == null) {
    return null;
  }
  Instant cachedInstant = lsnToInstantCache.get(lsn);
  if (cachedInstant != null) {
    return cachedInstant;
  }
  return prepareQueryAndMap(query, statement -> {
    statement.setBytes(1, lsn.getBinary());
  }, singleResultMapper(rs -> {
    final Timestamp ts = rs.getTimestamp(1);
    final Instant ret = (ts == null) ? null : ts.toInstant();
    LOGGER.trace("Timestamp of lsn {} is {}", lsn, ret);
    if (ret != null) {
      lsnToInstantCache.put(lsn, ret);
    }
    return ret;
  }, "LSN to timestamp query must return exactly one value"));
}

相关文章