Example usage for java.sql Timestamp Timestamp

List of usage examples for java.sql Timestamp Timestamp

Introduction

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

Prototype

public Timestamp(long time) 

Source Link

Document

Constructs a Timestamp object using a milliseconds time value.

Usage

From source file:com.fluke.database.dataservice.IntraDayDaoTest.java

public void testBatchUpdate() {
    IntraDayDao dao = new IntraDayDao();
    IntradayTicker ticker1 = new IntradayTicker();
    ticker1.setOpenPrice(100);/*  ww  w .  j a va 2s.com*/
    ticker1.setTime(new Timestamp(1438746899l));
    IntradayTicker ticker2 = new IntradayTicker();
    ticker2.setOpenPrice(100);
    ticker2.setTime(new Timestamp(1438777899l));
    dao.insertBatch("xyz", Arrays.asList(ticker1, ticker2));

}

From source file:AIR.Common.Utilities.Dates.java

public static Timestamp getTimestamp(Date date) {
    if (date == null)
        return null;
    // TODO Shiva what about timezone?
    Timestamp ts = new Timestamp(date.getTime());
    return ts;//from   w w  w.  j  ava 2s . c  om
}

From source file:uk.org.funcube.fcdw.server.extract.csv.HighResCsvExtractor.java

@Transactional(readOnly = true, propagation = Propagation.REQUIRED)
public void extract(long satelliteId) {

    Timestamp latestSatelliteTime = highResolutionDao.getLatestSatelliteTime(satelliteId);

    Timestamp since = new Timestamp(latestSatelliteTime.getTime() - (60 * 60 * 1000));

    List<HighResolutionEntity> highResOneHour = highResolutionDao.getSinceSatelliteTime(satelliteId, since);

    if (highResOneHour.size() == 0) {
        return;/*from   w  ww.  j a  v a 2  s  . c o  m*/
    }

    File fileLocation = new File(System.getProperty("csv.hires"));

    if (fileLocation.exists()) {
        fileLocation.delete();
    }

    try {
        // use FileWriter constructor that specifies open for appending
        CsvWriter csvOutput = new CsvWriter(new FileWriter(fileLocation, true), ',');

        // write out the headers
        csvOutput.write("Satellite Date/Time UTC");
        csvOutput.write("Sun Sensor +X log Lux");
        csvOutput.write("Sun Sensor +Y log Lux");
        csvOutput.write("Sun Sensor -Y log Lux");
        csvOutput.write("Sun Sensor +Z log Lux");
        csvOutput.write("Sun Sensor -Z log Lux");
        csvOutput.write("Tot. Photo Curr. mA");
        csvOutput.write("Battery mV");
        csvOutput.endRecord();

        long tsLong = 0;
        String c1 = "";
        String c2 = "";
        String c3 = "";
        String c4 = "";
        String c5 = "";
        String c6 = "";
        String c7 = "";

        for (HighResolutionEntity entity : highResOneHour) {

            Timestamp satelliteTime = entity.getSatelliteTime();

            if (tsLong == 0) {
                tsLong = satelliteTime.getTime();
                c1 = String.format("%5.3f", new Double(SOL_ILLUMINATION[entity.getC1().intValue()]));
                c2 = String.format("%5.3f", new Double(SOL_ILLUMINATION[entity.getC2().intValue()]));
                c3 = String.format("%5.3f", new Double(SOL_ILLUMINATION[entity.getC3().intValue()]));
                c4 = String.format("%5.3f", new Double(SOL_ILLUMINATION[entity.getC4().intValue()]));
                c5 = String.format("%5.3f", new Double(SOL_ILLUMINATION[entity.getC5().intValue()]));
                c6 = String.format("%4.0f", new Double(entity.getC6() * 2.0));
                c7 = String.format("%3.0f", new Double(entity.getC7() * 2.0));

                writeRecord(csvOutput, satelliteTime, c1, c2, c3, c4, c5, c6, c7);
            } else {

                final long timeDiff = satelliteTime.getTime() - tsLong;
                if (timeDiff > 1000) {
                    // fill in the gaps
                    long gaps = (timeDiff / 1000);
                    for (long i = 1; i < gaps; i++) {
                        Timestamp intervalTime = new Timestamp(tsLong + (1000 * i));
                        writeRecord(csvOutput, intervalTime, c1, c2, c3, c4, c5, c6, c7);
                    }
                }

                c1 = String.format("%5.3f", new Double(SOL_ILLUMINATION[entity.getC1().intValue()]));
                c2 = String.format("%5.3f", new Double(SOL_ILLUMINATION[entity.getC2().intValue()]));
                c3 = String.format("%5.3f", new Double(SOL_ILLUMINATION[entity.getC3().intValue()]));
                c4 = String.format("%5.3f", new Double(SOL_ILLUMINATION[entity.getC4().intValue()]));
                c5 = String.format("%5.3f", new Double(SOL_ILLUMINATION[entity.getC5().intValue()]));
                c6 = String.format("%4.0f", new Double(entity.getC6() * 2.0));
                c7 = String.format("%3.0f", new Double(entity.getC7() * 2.0));

                writeRecord(csvOutput, satelliteTime, c1, c2, c3, c4, c5, c6, c7);

                tsLong = satelliteTime.getTime();
            }
        }

        csvOutput.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:org.hoteia.qalingo.app.business.job.email.EmailCleanerTasklet.java

public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
    GregorianCalendar calendar = new GregorianCalendar();
    int day = calendar.get(GregorianCalendar.DAY_OF_YEAR);

    // TODO : Denis : 20130924 : add number of day configuration in database

    calendar.set(GregorianCalendar.DAY_OF_YEAR, day - 7);
    int row = emailService.deleteSendedEmail(new Timestamp(calendar.getTimeInMillis()));
    logger.debug(row + " emails deleted");
    return RepeatStatus.FINISHED;
}

From source file:org.killbill.billing.plugin.dao.PluginDao.java

protected static Timestamp toTimestamp(@Nullable final DateTime dateTime) {
    return dateTime == null ? null : new Timestamp(dateTime.getMillis());
}

From source file:org.hoteia.qalingo.app.business.job.status.ServerStatusCleanerTasklet.java

public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
    GregorianCalendar calendar = new GregorianCalendar();
    int day = calendar.get(GregorianCalendar.DAY_OF_YEAR);

    // TODO : Denis : 20131209 : add number of day configuration in database ?

    calendar.set(GregorianCalendar.DAY_OF_YEAR, day - 7);
    int row = serverService.deleteSendedServerStatus(new Timestamp(calendar.getTimeInMillis()));
    logger.debug(row + " server status deleted");
    return RepeatStatus.FINISHED;
}

From source file:com.ge.apm.service.converter.DateConverter.java

protected Object convertToDate(Class type, Object value, String pattern) {
    SimpleDateFormat sdf = new SimpleDateFormat(pattern);
    if (value instanceof String) {
        try {/*w  w w  .jav a  2s  . c o m*/
            if (StringUtils.isEmpty(value.toString())) {
                return null;
            }
            Date date = sdf.parse((String) value);
            if (type.equals(Timestamp.class)) {
                return new Timestamp(date.getTime());
            }
            return date;
        } catch (Exception pe) {
            return null;
        }
    } else if (value instanceof Date) {
        return value;
    }

    throw new ConversionException("?? " + value.getClass().getName() + "  " + type.getName());
}

From source file:com.traffic.web.action.UserAction.java

public String addUser() {
    TbUser tu = new TbUser();
    tu.setUserId(userId);//from  w w  w.j  a  v a 2s  . c  o m
    tu.setUserPassword(userPassword);
    tu.setUserName(userName);
    tu.setPhoneNumber(phoneNumber);
    tu.setRoleId(roleId);
    tu.setRemark(remark);
    tu.setJoinTime(new Timestamp(new Date().getTime()));
    tu.setOpenId(openId);
    tu.setIdentityCard(identityCard);
    tu.setDirvingLicense(dirvingLicense);
    tu.setStatus("");
    result = userService.addUser(tu);
    return "success";
}

From source file:com.microsoft.sqlserver.testframework.sqlType.SqlDateTime2.java

public Object createdata() {
    Timestamp temp = new Timestamp(ThreadLocalRandom.current().nextLong(((Timestamp) minvalue).getTime(),
            ((Timestamp) maxvalue).getTime()));
    temp.setNanos(0);/*from   ww w  .  j av  a  2 s.co  m*/
    String timeNano = temp.toString().substring(0, temp.toString().length() - 1)
            + RandomStringUtils.randomNumeric(this.precision);
    // can pass string rather than converting to LocalDateTime, but leaving
    // it unchanged for now to handle prepared statements
    return LocalDateTime.parse(timeNano, formatter);
}

From source file:com.memetro.android.notifications.NotificationUtils.java

/**
 * Stores the registration id, app versionCode, and expiration time in the
 * application's {@code SharedPreferences}.
 *
 * @param context application's context.
 * @param regId registration id// w  w  w.  j  ava 2s  .co m
 */
public static void setRegistrationId(Context context, String regId) {
    final SharedPreferences prefs = getGCMPreferences(context);
    int appVersion = getAppVersion(context);
    Log.v(TAG, "Saving regId on app version " + appVersion);
    SharedPreferences.Editor editor = prefs.edit();
    editor.putString(PROPERTY_REG_ID, regId);
    editor.putInt(PROPERTY_APP_VERSION, appVersion);
    long expirationTime = System.currentTimeMillis() + REGISTRATION_EXPIRY_TIME_MS;

    Log.v(TAG, "Setting registration expiry time to " + new Timestamp(expirationTime));
    editor.putLong(PROPERTY_ON_SERVER_EXPIRATION_TIME, expirationTime);
    editor.commit();
}