Example usage for java.sql Timestamp getTime

List of usage examples for java.sql Timestamp getTime

Introduction

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

Prototype

public long getTime() 

Source Link

Document

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

Usage

From source file:org.apache.stratos.status.monitor.internal.core.MySQLConnector.java

/**
 * Gets the list of all the service state details.
 *
 * @return the list of the service state details.
 * @throws Exception, if the retrieval of the service state details failed.
 *///from   ww w. j  a v a2 s.c  om
public static List<ServiceStateDetailInfoBean> getAllServiceStateDetail() throws Exception {
    List<ServiceStateDetailInfoBean> stateDetailList = new ArrayList<ServiceStateDetailInfoBean>();

    ResultSet rs;
    Statement stmtCon = conn.createStatement();
    String sql = StatusMonitorConstants.GET_ALL_STATE_DETAIL_SQL;
    stmtCon.executeQuery(sql);
    rs = stmtCon.getResultSet();
    String service;
    String serviceStateDetail;
    Timestamp stateLoggedTime;
    Timestamp detailLoggedTime;

    ServiceStateDetailInfoBean serviceStateDetailInfoBean;

    try {
        while (rs.next()) {
            serviceStateDetailInfoBean = new ServiceStateDetailInfoBean();

            service = rs.getString(StatusMonitorConstants.SERVICE_WSL_NAME);
            stateLoggedTime = rs.getTimestamp(StatusMonitorConstants.SERVICE_STATE_WSL_TIMESTAMP);
            detailLoggedTime = rs.getTimestamp(StatusMonitorConstants.SERVICE_STATE_DETAIL_WSL_TIMESTAMP);
            serviceStateDetail = rs.getString(StatusMonitorConstants.SERVICE_STATE_DETAIL);

            serviceStateDetailInfoBean.setService(service);
            serviceStateDetailInfoBean.setStateLoggedTime(stateLoggedTime.getTime());
            serviceStateDetailInfoBean.setServiceStateDetail(serviceStateDetail);
            serviceStateDetailInfoBean.setDetailLoggedTime(detailLoggedTime.getTime());

            stateDetailList.add(serviceStateDetailInfoBean);
        }
    } catch (SQLException e) {
        String msg = "Getting the serviceID failed";
        log.error(msg, e);
        throw new SQLException(msg, e);
    } finally {
        rs.close();
        stmtCon.close();
    }
    return stateDetailList;
}

From source file:egovframework.asadal.asapro.com.utl.fcc.service.AsaproEgovStringUtil.java

License:asdf

/**
 * ??? ?   ?17??TIMESTAMP?  /*from w  ww.ja v  a 2 s . com*/
 *
 * @param
 * @return Timestamp 
 * @exception MyException
 * @see
 */
public static String getTimeStamp() {

    String rtnStr = null;

    // ?    (?--? :::(?? ))
    String pattern = "yyyyMMddhhmmssSSS";

    try {
        SimpleDateFormat sdfCurrent = new SimpleDateFormat(pattern, Locale.KOREA);
        Timestamp ts = new Timestamp(System.currentTimeMillis());

        rtnStr = sdfCurrent.format(ts.getTime());
    } catch (Exception e) {
        log.error(e.getMessage());
    }

    return rtnStr;
}

From source file:egovframework.asadal.asapro.com.cmm.util.AsaproEgovStringUtil.java

License:asdf

/**
 * ??? ?   ?17??TIMESTAMP?  /* w  w  w. j av a 2s. c  om*/
 *
 * @param
 * @return Timestamp 
 * @exception MyException
 * @see
 */
public static String getTimeStamp() {

    String rtnStr = null;

    // ?    (?--? :::(?? ))
    String pattern = "yyyyMMddhhmmssSSS";

    try {
        SimpleDateFormat sdfCurrent = new SimpleDateFormat(pattern, Locale.KOREA);
        Timestamp ts = new Timestamp(System.currentTimeMillis());

        rtnStr = sdfCurrent.format(ts.getTime());
    } catch (NullPointerException e) {
        log.debug(e.getMessage());
    } catch (IllegalArgumentException e) {
        log.debug(e.getMessage());
    }

    return rtnStr;
}

From source file:ome.services.sharing.ShareBean.java

/**
 * Convert a {@link Timestamp expiration} into a long which can be set on
 * {@link Session#setTimeToLive(Long)}./*from w  ww . j  a v a  2 s  .c  o  m*/
 * 
 * @return the time in milliseconds that this session can exist.
 */
public static long expirationAsLong(long started, Timestamp expiration) {
    long time;
    if (expiration != null) {
        time = expiration.getTime();
        if (time < System.currentTimeMillis()) {
            throw new ApiUsageException("Expiration time must be in the future.");
        }
    } else {
        time = Long.MAX_VALUE;
    }

    return time - started;
}

From source file:org.apache.nifi.avro.AvroTypeUtil.java

private static Long getLongFromTimestamp(final Object rawValue, final Schema fieldSchema,
        final String fieldName) {
    final String format = AvroTypeUtil.determineDataType(fieldSchema).getFormat();
    Timestamp t = DataTypeUtils.toTimestamp(rawValue, () -> DataTypeUtils.getDateFormat(format), fieldName);
    return t.getTime();
}

From source file:com.concursive.connect.web.portal.PortalUtils.java

public static void populateObject(Object bean, ActionRequest request) {
    String nestedAttribute = "_";

    Enumeration en = request.getParameterNames();
    String paramName = null;/*from  ww  w . jav a 2s .  c  om*/
    while (en.hasMoreElements()) {
        paramName = (String) en.nextElement();

        // a form has been submitted and requested to be auto-populated,
        // so we do that here..going through every element and trying
        // to call a setXXX() method on the bean object passed in for the value
        // of the request parameter currently being checked.
        String[] paramValues = request.getParameterValues(paramName);
        if (paramValues.length > 1) {
            ObjectUtils.setParam(bean, paramName, paramValues, nestedAttribute);
        } else {
            ObjectUtils.setParam(bean, paramName, paramValues[0], nestedAttribute);
        }
    }

    // TODO: currently for ticket and ticket history
    //ObjectUtils.invokeMethod(bean, "setRequestItems", new HttpRequestContext(request));
    // Check for valid user
    User thisUser = (User) request.getAttribute(Constants.REQUEST_USER);
    if (thisUser != null) {
        // Populate date/time fields using the user's timezone and locale
        if (thisUser.getTimeZone() != null) {
            ArrayList timeParams = (ArrayList) ObjectUtils.getObject(bean, "TimeZoneParams");
            if (timeParams != null) {
                Calendar cal = Calendar.getInstance();
                Iterator i = timeParams.iterator();
                while (i.hasNext()) {
                    // The property that can be set
                    String name = (String) i.next();
                    // See if it is in the request
                    String value = request.getParameter(name);
                    if (value != null) {
                        // See if time is in request too
                        String hourValue = request.getParameter(name + "Hour");
                        if (hourValue == null) {
                            // Date fields: 1-1 mapping between HTML field and Java property
                            ObjectUtils.setParam(bean, name,
                                    DateUtils.getUserToServerDateTimeString(
                                            TimeZone.getTimeZone(thisUser.getTimeZone()), DateFormat.SHORT,
                                            DateFormat.LONG, value, thisUser.getLocale()));
                        } else {
                            // Date & Time fields: 4-1 mapping between HTML fields and Java property
                            try {
                                Timestamp timestamp = DatabaseUtils.parseDateToTimestamp(value,
                                        thisUser.getLocale());
                                cal.setTimeInMillis(timestamp.getTime());
                                int hour = Integer.parseInt(hourValue);
                                int minute = Integer.parseInt(request.getParameter(name + "Minute"));
                                String ampmString = request.getParameter(name + "AMPM");
                                if (ampmString != null) {
                                    int ampm = Integer.parseInt(ampmString);
                                    if (ampm == Calendar.AM) {
                                        if (hour == 12) {
                                            hour = 0;
                                        }
                                    } else {
                                        if (hour < 12) {
                                            hour += 12;
                                        }
                                    }
                                }
                                cal.set(Calendar.HOUR_OF_DAY, hour);
                                cal.set(Calendar.MINUTE, minute);
                                cal.setTimeZone(TimeZone.getTimeZone(thisUser.getTimeZone()));
                                ObjectUtils.setParam(bean, name, new Timestamp(cal.getTimeInMillis()));
                            } catch (Exception dateE) {
                            }
                        }
                    }
                }
            }
        }

        // Populate number fields using the user's locale
        if (thisUser.getLocale() != null) {
            ArrayList numberParams = (ArrayList) ObjectUtils.getObject(bean, "NumberParams");
            if (numberParams != null) {
                NumberFormat nf = NumberFormat.getInstance(thisUser.getLocale());
                Iterator i = numberParams.iterator();
                while (i.hasNext()) {
                    // The property that can be set
                    String name = (String) i.next();
                    // See if it is in the request
                    String value = (String) request.getParameter(name);
                    if (value != null && !"".equals(value)) {
                        try {
                            // Parse the value
                            ObjectUtils.setParam(bean, name, nf.parse(value).doubleValue());
                        } catch (Exception e) {
                            //e.printStackTrace(System.out);
                        }
                    }
                }
            }
        }
    }
}

From source file:com.persistent.cloudninja.mapper.InstanceHealthActiveUserRowMapper.java

@Override
public InstanceHealthActiveUserEntity mapRow(ResultSet rs, int rowNum) throws SQLException {
    InstanceHealthActiveUserEntity uniqueUser = new InstanceHealthActiveUserEntity();
    uniqueUser.setCount(rs.getInt("ActiveUsers"));
    Timestamp time = rs.getTimestamp("TimeInterval");
    uniqueUser.setTimeStamp(new Date(time.getTime()));

    return uniqueUser;
}

From source file:de.fraunhofer.iosb.ilt.sta.persistence.postgres.PropertyHelper.java

private static TimeInterval intervalFromTimes(Timestamp timeStart, Timestamp timeEnd) {
    if (timeStart == null) {
        timeStart = Timestamp.valueOf(LocalDateTime.MAX);
    }/*  w  w  w  .  j  ava  2 s.  co  m*/
    if (timeEnd == null) {
        timeEnd = Timestamp.valueOf(LocalDateTime.MIN);
    }
    if (timeEnd.before(timeStart)) {
        return null;
    } else {
        return TimeInterval.create(timeStart.getTime(), timeEnd.getTime());
    }
}

From source file:org.shengrui.oa.util.UtilDateTime.java

public static java.sql.Timestamp getDayStart(java.sql.Timestamp stamp, int daysLater) {
    Calendar tempCal = Calendar.getInstance();

    tempCal.setTime(new java.util.Date(stamp.getTime()));
    tempCal.set(tempCal.get(Calendar.YEAR), tempCal.get(Calendar.MONTH), tempCal.get(Calendar.DAY_OF_MONTH), 0,
            0, 0);//from ww  w  .  j  a  v  a2s  . c om
    tempCal.add(Calendar.DAY_OF_MONTH, daysLater);
    return new java.sql.Timestamp(tempCal.getTime().getTime());
}

From source file:org.shengrui.oa.util.UtilDateTime.java

public static java.sql.Timestamp getDayEnd(java.sql.Timestamp stamp, int daysLater) {
    Calendar tempCal = Calendar.getInstance();

    tempCal.setTime(new java.util.Date(stamp.getTime()));
    tempCal.set(tempCal.get(Calendar.YEAR), tempCal.get(Calendar.MONTH), tempCal.get(Calendar.DAY_OF_MONTH), 23,
            59, 59);/*from   w  w  w  . j  a  va2 s . c  om*/
    tempCal.add(Calendar.DAY_OF_MONTH, daysLater);
    return new java.sql.Timestamp(tempCal.getTime().getTime());
}