Tabnine Logo
Timestamp
Code IndexAdd Tabnine to your IDE (free)

How to use
Timestamp
in
java.sql

Best Java code snippets using java.sql.Timestamp (Showing top 20 results out of 18,639)

Refine searchRefine arrow

  • Date
  • Date
  • PreparedStatement
  • Calendar
  • Connection
  • Time
  • ResultSet
  • SimpleDateFormat
origin: jfinal/jfinal

  @Override
  public java.sql.Timestamp convert(String s) throws ParseException {
    if (timeStampWithoutSecPatternLen == s.length()) {
      s = s + ":00";
    }
    if (s.length() > dateLen) {
      return java.sql.Timestamp.valueOf(s);
    }
    else {
      return new java.sql.Timestamp(new SimpleDateFormat(datePattern).parse(s).getTime());
    }
  }
}
origin: elasticjob/elastic-job-lite

/**
 * 获取最近一条运行中的任务统计数据.
 * 
 * @return 运行中的任务统计数据对象
 */
public Optional<JobRunningStatistics> findLatestJobRunningStatistics() {
  JobRunningStatistics result = null;
  String sql = String.format("SELECT id, running_count, statistics_time, creation_time FROM %s order by id DESC LIMIT 1", 
      TABLE_JOB_RUNNING_STATISTICS);
  try (
      Connection conn = dataSource.getConnection();
      PreparedStatement preparedStatement = conn.prepareStatement(sql);
      ResultSet resultSet = preparedStatement.executeQuery()
      ) {
    while (resultSet.next()) {
      result = new JobRunningStatistics(resultSet.getLong(1), resultSet.getInt(2), 
          new Date(resultSet.getTimestamp(3).getTime()), new Date(resultSet.getTimestamp(4).getTime()));
    }
  } catch (final SQLException ex) {
    // TODO 记录失败直接输出日志,未来可考虑配置化
    log.error("Fetch latest jobRunningStatistics from DB error:", ex);
  }
  return Optional.fromNullable(result);
}

origin: hibernate/hibernate-orm

@Override
public String objectToSQLString(Date value, Dialect dialect) throws Exception {
  final Timestamp ts = Timestamp.class.isInstance( value )
      ? ( Timestamp ) value
      : new Timestamp( value.getTime() );
  // TODO : use JDBC date literal escape syntax? -> {d 'date-string'} in yyyy-mm-dd hh:mm:ss[.f...] format
  return StringType.INSTANCE.objectToSQLString( ts.toString(), dialect );
}
origin: apache/flink

private static Timestamp copyTimestamp(Object o) {
  if (o == null) {
    return null;
  } else {
    long millis = ((Timestamp) o).getTime();
    int nanos = ((Timestamp) o).getNanos();
    Timestamp copy = new Timestamp(millis);
    copy.setNanos(nanos);
    return copy;
  }
}
origin: apache/flink

@Override
public Timestamp copy(Timestamp from, Timestamp reuse) {
  if (from == null) {
    return null;
  }
  reuse.setTime(from.getTime());
  reuse.setNanos(from.getNanos());
  return reuse;
}
origin: com.h2database/h2

private static String formatTimestamp(long t, long start) {
  String x = new Timestamp(t).toString();
  String s = x.substring(0, 19);
  s += " (+" + ((t - start) / 1000) + " s)";
  return s;
}
origin: stackoverflow.com

 java.util.Date utilDate = new java.util.Date();
Calendar cal = Calendar.getInstance();
cal.setTime(utilDate);
cal.set(Calendar.MILLISECOND, 0);
System.out.println(new java.sql.Timestamp(utilDate.getTime()));
System.out.println(new java.sql.Timestamp(cal.getTimeInMillis()));
origin: hibernate/hibernate-orm

@SuppressWarnings({ "unchecked" })
public <X> X unwrap(Calendar value, Class<X> type, WrapperOptions options) {
  if ( value == null ) {
    return null;
  }
  if ( Calendar.class.isAssignableFrom( type ) ) {
    return (X) value;
  }
  if ( java.sql.Date.class.isAssignableFrom( type ) ) {
    return (X) new java.sql.Date( value.getTimeInMillis() );
  }
  if ( java.sql.Time.class.isAssignableFrom( type ) ) {
    return (X) new java.sql.Time( value.getTimeInMillis() );
  }
  if ( java.sql.Timestamp.class.isAssignableFrom( type ) ) {
    return (X) new java.sql.Timestamp( value.getTimeInMillis() );
  }
  if ( java.util.Date.class.isAssignableFrom( type ) ) {
    return (X) new  java.util.Date( value.getTimeInMillis() );
  }
  throw unknownUnwrap( type );
}
origin: org.codehaus.groovy/groovy

@Deprecated
public static Timestamp plus(Timestamp self, int days) {
  Calendar calendar = Calendar.getInstance();
  calendar.setTime(self);
  calendar.add(Calendar.DATE, days);
  Timestamp ts = new Timestamp(calendar.getTime().getTime());
  ts.setNanos(self.getNanos());
  return ts;
}
origin: hibernate/hibernate-orm

  @Override
  public Date deepCopyNotNull(Date value) {
    if ( value instanceof Timestamp ) {
      Timestamp orig = (Timestamp) value;
      Timestamp ts = new Timestamp( orig.getTime() );
      ts.setNanos( orig.getNanos() );
      return ts;
    }
    else {
      return new Date( value.getTime() );
    }
  }
}
origin: elastic/elasticsearch-hadoop

@Test
public void testTimestamp() {
  Date d = new Date(0);
  Timestamp ts = new Timestamp(0);
  assertThat(jdkTypeToJson(ts), containsString(new SimpleDateFormat("yyyy-MM-dd").format(d)));
}
origin: apache/incubator-shardingsphere

private Timestamp getTimestamp(final MySQLPacketPayload payload) {
  Calendar calendar = Calendar.getInstance();
  calendar.set(0, Calendar.JANUARY, 0, payload.readInt1(), payload.readInt1(), payload.readInt1());
  Timestamp result = new Timestamp(calendar.getTimeInMillis());
  result.setNanos(0);
  return result;
}

origin: spring-projects/spring-framework

ps.setString(paramIndex, inValue.toString());
ps.setNString(paramIndex, inValue.toString());
    ps.setNClob(paramIndex, new StringReader(strVal), strVal.length());
    ps.setDate(paramIndex, new java.sql.Date(((java.util.Date) inValue).getTime()));
  ps.setDate(paramIndex, new java.sql.Date(cal.getTime().getTime()), cal);
    ps.setTime(paramIndex, new java.sql.Time(((java.util.Date) inValue).getTime()));
  ps.setTime(paramIndex, new java.sql.Time(cal.getTime().getTime()), cal);
    ps.setTimestamp(paramIndex, new java.sql.Timestamp(((java.util.Date) inValue).getTime()));
  ps.setTimestamp(paramIndex, new java.sql.Timestamp(cal.getTime().getTime()), cal);
  "Oracle".equals(ps.getConnection().getMetaData().getDatabaseProductName()))) {
if (isStringValue(inValue.getClass())) {
  ps.setString(paramIndex, inValue.toString());
  ps.setTimestamp(paramIndex, new java.sql.Timestamp(((java.util.Date) inValue).getTime()));
  ps.setTimestamp(paramIndex, new java.sql.Timestamp(cal.getTime().getTime()), cal);
origin: alibaba/druid

protected void readFieldValue(Object object, FieldInfo field, ResultSet rs, int paramIndex) throws SQLException {
  Class<?> fieldType = field.getFieldType();
  Object fieldValue = null;
  if (fieldType.equals(int.class) || fieldType.equals(Integer.class)) {
    fieldValue = rs.getInt(paramIndex);
  } else if (fieldType.equals(long.class) || fieldType.equals(Long.class)) {
    fieldValue = rs.getLong(paramIndex);
  } else if (fieldType.equals(String.class)) {
    fieldValue = rs.getString(paramIndex);
  } else if (fieldType.equals(Date.class)) {
    Timestamp timestamp = rs.getTimestamp(paramIndex);
    if (timestamp != null) {
      fieldValue = new Date(timestamp.getTime());
    }
  } else {
    throw new UnsupportedOperationException();
  }
  try {
    field.getField().set(object, fieldValue);
  } catch (IllegalArgumentException e) {
    throw new DruidRuntimeException("set field error" + field.getField(), e);
  } catch (IllegalAccessException e) {
    throw new DruidRuntimeException("set field error" + field.getField(), e);
  }
}
origin: spring-projects/spring-framework

@Test
public void testSetParameterValueWithDateAndUnknownType() throws SQLException {
  java.util.Date date = new java.util.Date(1000);
  StatementCreatorUtils.setParameterValue(preparedStatement, 1, SqlTypeValue.TYPE_UNKNOWN, null, date);
  verify(preparedStatement).setTimestamp(1, new java.sql.Timestamp(1000));
}
origin: apache/hive

private byte[] encodeTime(Timestamp timestamp) {
 ByteBuffer encoded;
 long time = timestamp.getTime();
 try {
  String formatted = dateFormat.format(new Date(time));
  encoded = Text.encode(formatted);
 } catch (CharacterCodingException e) {
  throw new RuntimeException(e);
 }
 return Arrays.copyOf(encoded.array(), encoded.limit());
}
origin: elasticjob/elastic-job-lite

private boolean updateJobExecutionEventWhenSuccess(final JobExecutionEvent jobExecutionEvent) {
  boolean result = false;
  String sql = "UPDATE `" + TABLE_JOB_EXECUTION_LOG + "` SET `is_success` = ?, `complete_time` = ? WHERE id = ?";
  try (
      Connection conn = dataSource.getConnection();
      PreparedStatement preparedStatement = conn.prepareStatement(sql)) {
    preparedStatement.setBoolean(1, jobExecutionEvent.isSuccess());
    preparedStatement.setTimestamp(2, new Timestamp(jobExecutionEvent.getCompleteTime().getTime()));
    preparedStatement.setString(3, jobExecutionEvent.getId());
    if (0 == preparedStatement.executeUpdate()) {
      return insertJobExecutionEventWhenSuccess(jobExecutionEvent);
    }
    result = true;
  } catch (final SQLException ex) {
    // TODO 记录失败直接输出日志,未来可考虑配置化
    log.error(ex.getMessage());
  }
  return result;
}

origin: apache/flink

private Timestamp convertToTimestamp(Object object) {
  final long millis;
  if (object instanceof Long) {
    millis = (Long) object;
  } else {
    // use 'provided' Joda time
    final DateTime value = (DateTime) object;
    millis = value.toDate().getTime();
  }
  return new Timestamp(millis - LOCAL_TZ.getOffset(millis));
}
origin: oblac/jodd

public Person createModesty() {
  Address benhome = new Address("NN Island", "Blue Cave", "ta", new Zipcode("82742"));
  Address benwork = new Address("44 Planetary St.", "Neptune", "Milkiway", new Zipcode("12345"));
  Calendar benCal = Calendar.getInstance();
  benCal.set(1986, Calendar.AUGUST, 8, 8, 11);
  Person ben = new Person("Modesty", "Blase", benCal.getTime(), benhome, benwork);
  benCal = Calendar.getInstance();
  benCal.set(1995, Calendar.MAY, 21, 8, 11);
  ben.setFirstBaseBallGame(new Timestamp(benCal.getTime().getTime()));
  ben.getHobbies().add("sneak");
  ben.getHobbies().add("kill");
  ben.getHobbies().add("fight");
  return ben;
}
origin: stackoverflow.com

 DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
Date date = dateFormat.parse("23/09/2007");
long time = date.getTime();
new Timestamp(time);
java.sqlTimestamp

Javadoc

A Java representation of the SQL TIMESTAMP type. It provides the capability of representing the SQL TIMESTAMP nanosecond value, in addition to the regular date/time value which has millisecond resolution.

The Timestamp class consists of a regular date/time value, where only the integral seconds value is stored, plus a nanoseconds value where the fractional seconds are stored.

The addition of the nanosecond value field to the Timestamp object makes it significantly different from the java.util.Date object which it extends. Users should be aware that Timestamp objects are not interchangable with java.util.Date objects when used outside the confines of the java.sql package.

Most used methods

  • <init>
    Returns a Timestamp object corresponding to the time represented by a supplied time value.
  • getTime
    Returns the time represented by this Timestamp object, as a long value containing the number of mill
  • valueOf
  • toString
    Returns the timestamp formatted as a String in the JDBC Timestamp Escape format, which is "yyyy-MM-d
  • getNanos
    Gets this Timestamp's nanosecond value
  • setNanos
    Sets the nanosecond value for this Timestamp.
  • toLocalDateTime
  • from
  • equals
    Tests to see if this timestamp is equal to a supplied timestamp.
  • compareTo
    Compares this Timestamp object with a supplied Timestampobject.
  • toInstant
  • after
    Returns true if this timestamp object is later than the supplied timestamp, otherwise returns false.
  • toInstant,
  • after,
  • setTime,
  • before,
  • hashCode,
  • getYear,
  • getDate,
  • getHours,
  • getMinutes,
  • getMonth

Popular in Java

  • Running tasks concurrently on multiple threads
  • getSupportFragmentManager (FragmentActivity)
  • getContentResolver (Context)
  • getResourceAsStream (ClassLoader)
  • List (java.util)
    An ordered collection (also known as a sequence). The user of this interface has precise control ove
  • PriorityQueue (java.util)
    A PriorityQueue holds elements on a priority heap, which orders the elements according to their natu
  • Scanner (java.util)
    A parser that parses a text string of primitive types and strings with the help of regular expressio
  • ConcurrentHashMap (java.util.concurrent)
    A plug-in replacement for JDK1.5 java.util.concurrent.ConcurrentHashMap. This version is based on or
  • JTextField (javax.swing)
  • Option (scala)
  • Top 15 Vim Plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now