Example usage for java.sql Timestamp setTime

List of usage examples for java.sql Timestamp setTime

Introduction

In this page you can find the example usage for java.sql Timestamp setTime.

Prototype

public void setTime(long time) 

Source Link

Document

Sets this Timestamp object to represent a point in time that is time milliseconds after January 1, 1970 00:00:00 GMT.

Usage

From source file:Main.java

public static void main(String[] args) {
    java.sql.Timestamp ts1 = java.sql.Timestamp.valueOf("2012-04-06 09:01:10");

    ts1.setTime(new Date().getTime());
    System.out.println(ts1);//from   www  . j  a  v a2s  . co m

}

From source file:com.arm.connector.bridge.core.Utils.java

public static java.sql.Timestamp convertDate(java.util.Date date) {
    java.sql.Timestamp sql_date = new java.sql.Timestamp(date.getTime());
    sql_date.setTime(date.getTime());
    return sql_date;
}

From source file:com.itdaoshi.dokeos.dao.UserDAObject.java

@Override
protected void initUserSpeclAttr(Object obj) throws Exception {
    User user = (User) obj;//from   w  ww.ja va  2s . c om
    user.setPassword(MD5.getMD5EncryptedString(user.getPassword()));
    user.setAuthSource("platform");
    user.setStatus(5);
    user.setCreatorID(1);
    user.setChatcallUserID(0);
    user.setLanguage("simpl_chinese");
    user.setActive(1);
    user.setHrDeptID(0);
    user.setChatcallText("");
    java.util.Date today = new java.util.Date();
    java.sql.Timestamp timestamp = new java.sql.Timestamp(today.getTime());
    user.setChatcallDate(timestamp);
    user.setRegistrationDate(timestamp);
    java.sql.Timestamp timestamp1 = new java.sql.Timestamp(today.getTime());
    timestamp1.setTime(25414645);
    user.setExpirationDate(timestamp1);
}

From source file:com.commander4j.util.JUtility.java

/**
 * Method getSQLDateTime.//from  ww  w. j ava2s.  com
 * 
 * @return Timestamp
 */
public static Timestamp getSQLDateTime() {
    Calendar caldate = Calendar.getInstance();
    Timestamp t = new Timestamp(caldate.getTimeInMillis());
    t.setTime(caldate.getTimeInMillis());

    return t;
}

From source file:com.commander4j.util.JUtility.java

/**
 * Method getTimestampFromDate.//ww w .ja v  a  2s .co m
 * 
 * @param d
 *            Date
 * @return Timestamp
 */
public static Timestamp getTimestampFromDate(Date d) {
    Calendar caldate = Calendar.getInstance();
    caldate.setTime(d);

    Timestamp t = new Timestamp(caldate.getTimeInMillis());
    t.setNanos(0);
    t.setTime(caldate.getTimeInMillis());

    return t;
}

From source file:edu.northwestern.bioinformatics.studycalendar.service.SubjectService.java

Date shiftDayByOne(Date date) {
    java.sql.Timestamp timestampTo = new java.sql.Timestamp(date.getTime());
    long oneDay = 24 * 60 * 60 * 1000;
    timestampTo.setTime(timestampTo.getTime() + oneDay);
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    String dateString = df.format(timestampTo);
    Date d1;/*ww w . j  a  v a  2 s . c  o m*/
    try {
        d1 = df.parse(dateString);
    } catch (ParseException e) {
        log.debug("Exception " + e);
        d1 = date;
    }
    return d1;
}

From source file:com.oltpbenchmark.benchmarks.auctionmark.AuctionMarkProfile.java

private Timestamp getScaledCurrentTimestamp(Timestamp time) {
    assert (this.clientStartTime != null);
    tmp_now.setTime(System.currentTimeMillis());
    time.setTime(AuctionMarkUtil.getScaledTimestamp(this.loaderStartTime, this.clientStartTime, tmp_now));
    if (LOG.isTraceEnabled())
        LOG.trace(String.format("Scaled:%d / Now:%d / BenchmarkStart:%d / ClientStart:%d", time.getTime(),
                tmp_now.getTime(), this.loaderStartTime.getTime(), this.clientStartTime.getTime()));
    return (time);
}

From source file:beproject.MainGUI.java

void getTimeLineData(TimeSeriesCollection t) throws SQLException {
    Statement stmt = Initializer.inConn2.createStatement();
    ResultSet rs1 = stmt.executeQuery("select max(ts) from tweets");
    rs1.first();/*  w ww.j a v a  2s .co m*/
    Timestamp ts1 = rs1.getTimestamp(1);
    for (String tmp : ScheduledMoviesList.getMovieNames()) {
        TimeSeries t1 = new TimeSeries(tmp, Hour.class);
        Timestamp ts = (Timestamp) ts1.clone();
        for (int i = 0; i < 6; i++) {
            Date d1 = new java.util.Date(ts.getTime());
            Date d2 = new java.util.Date(ts.getTime() + 3600000);
            ResultSet rs = stmt
                    .executeQuery("select count(*) from tweets where moviename='" + tmp + "' and ts between '"
                            + Regression.sdf.format(d1) + "' and '" + Regression.sdf.format(d2) + "'");
            rs.first();
            //if(!rs.first())
            //  t1.addOrUpdate(new Hour(d1), 0);
            //else
            t1.addOrUpdate(new Hour(d1), rs.getInt(1));
            ts.setTime(ts.getTime() - 3600000);
        }
        t.addSeries(t1);
    }

}

From source file:org.apache.hadoop.hive.serde2.io.TimestampWritable.java

public static void setTimestamp(Timestamp t, byte[] bytes, int offset) {
    boolean hasDecimal = hasDecimal(bytes[offset]);
    t.setTime(((long) TimestampWritable.getSeconds(bytes, offset)) * 1000);
    if (hasDecimal) {
        t.setNanos(TimestampWritable.getNanos(bytes, offset + 4));
    }//from ww w  .  jav a 2  s .  c o  m
}

From source file:org.apache.openjpa.jdbc.sql.DBDictionary.java

/**
 * Set the given value as a parameter to the statement.
 *///  w  w w .  ja  v a2  s.  c  o  m
public void setTimestamp(PreparedStatement stmnt, int idx, Timestamp val, Calendar cal, Column col)
        throws SQLException {
    // ensure that we do not insert dates at a greater precision than
    // that at which they will be returned by a SELECT
    int rounded = (int) Math.round(val.getNanos() / (double) datePrecision);
    int nanos = rounded * datePrecision;
    if (nanos > 999999999) {
        // rollover to next second
        val.setTime(val.getTime() + 1000);
        nanos = 0;
    }

    Timestamp valForStmnt = new Timestamp(val.getTime());
    valForStmnt.setNanos(nanos);

    if (cal == null)
        stmnt.setTimestamp(idx, valForStmnt);
    else
        stmnt.setTimestamp(idx, valForStmnt, cal);
}