Example usage for java.sql Date getTime

List of usage examples for java.sql Date getTime

Introduction

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

Prototype

public long getTime() 

Source Link

Document

Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Date object.

Usage

From source file:no.polaric.aprsdb.DBSession.java

protected static Timestamp date2ts(java.util.Date d, int offset) {
    return new Timestamp((long) ((long) (d.getTime() + offset) / 100) * 100);
}

From source file:util.Support.java

/**
 * Convert three args day month year to type java.sql.Date
 *
 * @param day/*from   w  ww  .  java 2 s  .co  m*/
 * @param month
 * @param year
 * @return Date type: yyyy/MM/dd
 */
public static Date convertToDate(String day, String month, String year) {
    Date date = null;
    try {
        String bd = year + "/" + month + "/" + day;
        SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd");
        java.util.Date utilBD = df.parse(bd);
        date = new Date(utilBD.getTime());
    } catch (ParseException ex) {
        Logger.getLogger(Support.class.getName()).log(Level.SEVERE, null, ex);
    }
    return date;
}

From source file:org.apache.derbyDemo.scores.proc.Functions.java

/**
 * <p>//from w ww. ja v  a2 s.  c  o  m
 * Compute a Student's age given their birthday.
 * </p>
 */
public static int computeAge(java.sql.Date date) {
    long interval = System.currentTimeMillis() - date.getTime();
    return (int) (interval / MILLISECONDS_IN_YEAR);
}

From source file:org.wso2.carbon.issue.tracker.dao.impl.CommentDAOImpl.java

/**
 * Get current time to log DB//from  w ww. j  ava 2 s.c om
 *
 * @return {@link Timestamp}
 */
private static Timestamp getCurrentTimeStamp() {
    java.util.Date today = new java.util.Date();
    return new Timestamp(today.getTime());
}

From source file:org.pgptool.gui.encryption.implpgp.KeyFilesOperationsPgpImpl.java

private static void fillDates(KeyInfo ret, PGPPublicKey key) {
    ret.setCreatedOn(new Date(key.getCreationTime().getTime()));
    if (key.getValidSeconds() != 0) {
        java.util.Date expiresAt = DateUtils.addSeconds(key.getCreationTime(), (int) key.getValidSeconds());
        ret.setExpiresAt(new Date(expiresAt.getTime()));
    }/*ww w. java 2s.c o m*/
}

From source file:com.esofthead.mycollab.module.project.service.ibatis.GanttAssignmentServiceImpl.java

private static Date getDateWithNullValue(java.util.Date date) {
    return (date != null) ? new Date(date.getTime()) : null;
}

From source file:org.kuali.kra.negotiations.bo.NegotiationActivity.java

/**
 * /* w ww .  ja  va2s.c om*/
 * This method Calculates the number of days between the start date and either the end date when available or the current date.
 */
public static String getNumberOfDays(Date startDate, Date endDate) {
    if (startDate == null) {
        return "";
    } else {
        long start = startDate.getTime();
        final long end;
        if (endDate == null) {
            end = Calendar.getInstance().getTimeInMillis();
        } else {
            end = endDate.getTime();
        }
        return (((end - start) / MILLISECS_PER_DAY)) + "";
    }
}

From source file:yelpproject.DatabaseConnection.java

private static java.sql.Timestamp getCurrentTimeStamp() {

    java.util.Date today = new java.util.Date();
    return new java.sql.Timestamp(today.getTime());

}

From source file:ips1ap101.lib.base.util.TimeUtils.java

public static Timestamp newTimestamp(java.util.Date date) {
    if (date == null) {
        return null;
    } else {//from w  w  w  .  j a  va2 s.  c o m
        return new Timestamp(date.getTime());
    }
}

From source file:com.trackplus.ddl.DataReader.java

public static void writeDataToSql(DatabaseInfo databaseInfo, String dirName) throws DDLException {
    LOGGER.info("Exporting SQL data from \"" + databaseInfo.getUrl() + "\" ...");
    Map<String, String> info = new TreeMap<String, String>();
    java.util.Date d1 = new java.util.Date();
    info.put("start", d1.toString());
    info.put("driver", databaseInfo.getDriver());
    info.put("url", databaseInfo.getUrl());
    info.put("user", databaseInfo.getUser());
    info.put("user", databaseInfo.getUser());
    info.put("usePassword", Boolean.toString(databaseInfo.getPassword() != null));
    String databaseType = MetaDataBL.getDatabaseType(databaseInfo.getUrl());
    info.put(DATABASE_TYPE, databaseType);

    Connection connection = getConnection(databaseInfo);
    //log the database meta data information's
    logDatabaseMetaDataInfo(databaseInfo, connection);

    String[] versions = MetaDataBL.getVersions(connection);
    info.put(SYSTEM_VERSION, versions[0]);
    info.put(DB_VERSION, versions[1]);//from  ww  w  .java2s. c o m

    StringValueConverter stringValueConverter = new GenericStringValueConverter();

    BufferedWriter writer = createBufferedWriter(dirName + File.separator + FILE_NAME_DATA);
    BufferedWriter writerUpdate = createBufferedWriter(dirName + File.separator + FILE_NAME_DATA_UPDATE);
    BufferedWriter writerClean = createBufferedWriter(dirName + File.separator + FILE_NAME_DATA_CLEAN);
    BufferedWriter writerUpdateClean = createBufferedWriter(
            dirName + File.separator + FILE_NAME_DATA_UPDATE_CLEAN);
    BufferedWriter writerBlob = createBufferedWriter(dirName + File.separator + FILE_NAME_BLOB);

    int idx = 0;
    String[] tableNames = MetaDataBL.getTableNames();
    for (String tableName : tableNames) {
        LOGGER.debug("Processing table: " + tableName + "....");
        int count = getTableData(writer, writerClean, writerUpdate, writerUpdateClean, connection, tableName,
                stringValueConverter);
        info.put("_" + tableName, count + "");
        LOGGER.debug("Records exported:" + count + "\n");
        idx = idx + count;
    }
    LOGGER.debug("Processing blob data ....");
    int count = getBlobTableData(writerBlob, connection);
    LOGGER.debug(" Blob record exported:" + count + "\n");
    info.put("table_BLOB", count + "");
    idx = idx + count;

    try {
        char dataSeparator = (char) ASCII_DATA_SEPARATOR;
        writerBlob.write(dataSeparator);
        writerBlob.newLine();
        writerBlob.newLine();
        writerBlob.write("--TMSPROJECTEXCHANGE");
        writerBlob.newLine();
    } catch (IOException e) {
        LOGGER.error("Error on close blob stream file :" + e.getMessage());
        throw new DDLException(e.getMessage(), e);
    }

    LOGGER.debug("Processing clob data ....");
    count = getClobTableData(writerBlob, connection);
    LOGGER.debug(" Clob record exported:" + count + "\n");
    info.put("table_TMSPROJECTEXCHANGE", count + "");
    idx = idx + count;
    info.put("allData", idx + "");

    try {
        writer.flush();
        writer.close();

        writerClean.flush();
        writerClean.close();

        writerUpdate.flush();
        writerUpdate.close();

        writerUpdateClean.flush();
        writerUpdateClean.close();

        writerBlob.flush();
        writerBlob.close();
    } catch (IOException e) {
        LOGGER.error("Error on close stream file: " + e.getMessage());
        throw new DDLException(e.getMessage(), e);
    }

    try {
        connection.close();
    } catch (SQLException e) {
        throw new DDLException(e.getMessage(), e);
    }

    java.util.Date d2 = new java.util.Date();
    long timeSpend = d2.getTime() - d1.getTime();
    info.put("timeSpend", Long.toString(timeSpend));

    writeInfoToFile(info, dirName + File.separator + FILE_NAME_INFO);
    LOGGER.info("Data generated. All records found: " + idx + ". Time spend: " + timeSpend + " ms!");
}