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:eionet.webq.task.RemoveExpiredUserFilesTaskTest.java

@Test
public void performsRemovalBasedOnConfiguredProperties() throws Exception {
    removeExpiredUserFilesTask.setExpirationHours("1");
    removeExpiredUserFilesTask.removeExpiredUserFiles();

    ArgumentCaptor<SimpleExpression> criterionCaptor = ArgumentCaptor.forClass(SimpleExpression.class);
    verify(criteria).add(criterionCaptor.capture());

    Date expectedDate = DateUtils.addHours(new Date(), -expirationTimeInHours);
    Timestamp date = (Timestamp) criterionCaptor.getValue().getValue();
    assertEquals(expectedDate.getTime(), date.getTime(), 1000);
}

From source file:com.cyw.common.util.bean.DateConverter.java

protected Object convertToDate(Class type, Object value, String pattern) {
    DateFormat df = new SimpleDateFormat(pattern);
    if (value instanceof String) {
        try {//  ww  w  . j ava2  s.com
            if (StringUtils.isEmpty(value.toString())) {
                return null;
            }
            Date date = df.parse((String) value);
            if (type.equals(Timestamp.class)) {
                return new Timestamp(date.getTime());
            }
            return date;
        } catch (Exception pe) {
            pe.printStackTrace();
            throw new ConversionException("Error converting String to Date");
        }
    } else if (value instanceof Timestamp) {
        try {
            Timestamp timestamp = (Timestamp) value;
            Date date = new Date(timestamp.getTime());
            return date;
        } catch (Exception pe) {
            pe.printStackTrace();
            throw new ConversionException("Error converting Timestamp to Date");
        }
    } else if (value instanceof java.sql.Date) {
        try {
            java.sql.Date sqlDate = (java.sql.Date) value;
            return new Date(sqlDate.getTime());
        } catch (Exception pe) {
            pe.printStackTrace();
            throw new ConversionException("Error converting String to Date");
        }
    } else if (value instanceof Date) {
        return value;
    }
    throw new ConversionException("Could not convert " + value.getClass().getName() + " to " + type.getName());
}

From source file:com.vrv.common.converter.DateConverter.java

@SuppressWarnings("rawtypes")
protected Object convertToDate(Class type, Object value, String pattern) {
    DateFormat df = new SimpleDateFormat(pattern);
    if (value instanceof String) {
        try {//w  w  w .  jav  a2s  .com
            if (StringUtils.isEmpty(value.toString())) {
                return null;
            }
            Date date = df.parse((String) value);
            if (type.equals(Timestamp.class)) {
                return new Timestamp(date.getTime());
            }
            return date;
        } catch (Exception pe) {
            pe.printStackTrace();
            throw new ConversionException("Error converting String to Date");
        }
    } else if (value instanceof Timestamp) {
        try {
            Timestamp timestamp = (Timestamp) value;
            Date date = new Date(timestamp.getTime());
            return date;
        } catch (Exception pe) {
            pe.printStackTrace();
            throw new ConversionException("Error converting Timestamp to Date");
        }
    } else if (value instanceof java.sql.Date) {
        try {
            java.sql.Date sqlDate = (java.sql.Date) value;
            return new Date(sqlDate.getTime());
        } catch (Exception pe) {
            pe.printStackTrace();
            throw new ConversionException("Error converting String to Date");
        }
    } else if (value instanceof Date) {
        return value;
    }
    throw new ConversionException("Could not convert " + value.getClass().getName() + " to " + type.getName());
}

From source file:org.uaa.admin.resource.Apilogs.java

@Path("/requests")
@GET//from   w w w .j  a v a  2 s.  com
public String getRequestCount(@QueryParam("interval") Integer interval) {
    if (interval == null)
        interval = default_interval;

    Timestamp now = new Timestamp(System.currentTimeMillis());
    Integer count = apilogService.getRequestCount(interval, now.getTime());

    Map<String, Object> attrs = new LinkedHashMap<String, Object>();
    attrs.put("count", count);

    ResponseWithData res = new ResponseWithData(attrs);
    return res.toJson();
}

From source file:org.dozer.converters.DateConverter.java

public Object convert(Class destClass, Object srcObj) {
    final Class srcFieldClass = srcObj.getClass();

    long time;//from  ww w  . j  a  v  a  2  s. c o  m
    int nanos = 0;
    if (Calendar.class.isAssignableFrom(srcFieldClass)) {
        Calendar inVal = (Calendar) srcObj;
        time = inVal.getTime().getTime();
    } else if (Timestamp.class.isAssignableFrom(srcFieldClass)) {
        Timestamp timestamp = (Timestamp) srcObj;
        time = timestamp.getTime();
        nanos = timestamp.getNanos();
    } else if (java.util.Date.class.isAssignableFrom(srcFieldClass)) {
        time = ((java.util.Date) srcObj).getTime();
    } else if (XMLGregorianCalendar.class.isAssignableFrom(srcFieldClass)) {
        time = ((XMLGregorianCalendar) srcObj).toGregorianCalendar().getTimeInMillis();
    } else if (dateFormat != null && String.class.isAssignableFrom(srcObj.getClass())) {
        try {
            if ("".equals(srcObj)) {
                return null;
            }
            time = dateFormat.parse((String) srcObj).getTime();
        } catch (ParseException e) {
            throw new ConversionException("Unable to parse source object using specified date format", e);
        }
        // Default conversion
    } else {
        try {
            time = Long.parseLong(srcObj.toString());
        } catch (NumberFormatException e) {
            throw new ConversionException("Unable to determine time in millis of source object", e);
        }
    }

    try {
        if (Calendar.class.isAssignableFrom(destClass)) {
            Constructor constructor = destClass.getConstructor();
            Calendar result = (Calendar) constructor.newInstance();
            result.setTimeInMillis(time);
            return result;
        }
        Constructor constructor = destClass.getConstructor(Long.TYPE);
        Object result = constructor.newInstance(time);
        if (nanos != 0 && (Timestamp.class.isAssignableFrom(destClass))) {
            ((Timestamp) result).setNanos(nanos);
        }
        return result;
    } catch (Exception e) {
        throw new ConversionException(e);
    }
}

From source file:org.uaa.admin.resource.Apilogs.java

@Path("/addrs")
@GET//  ww w.j  a  va2s.  c  om
public String getUniqueAddrCount(@QueryParam("interval") Integer interval) {
    if (interval == null)
        interval = default_interval;

    Timestamp now = new Timestamp(System.currentTimeMillis());
    Integer count = apilogService.getUniqueAddrCount(interval, now.getTime());

    Map<String, Object> attrs = new LinkedHashMap<String, Object>();
    attrs.put("count", count);

    ResponseWithData res = new ResponseWithData(attrs);
    return res.toJson();
}

From source file:fitmon.DietAPI.java

public ArrayList<ArrayList<Food>> searchFood(String foodName) throws InvalidKeyException,
        NoSuchAlgorithmException, ParserConfigurationException, SAXException, IOException {
    xmlParser xParser = new xmlParser();
    ArrayList<ArrayList<Food>> listOfFoodList = new ArrayList<ArrayList<Food>>();
    ArrayList<String> list;
    String base = URLEncoder.encode("GET") + "&";
    base += "http%3A%2F%2Fplatform.fatsecret.com%2Frest%2Fserver.api&";
    String params;//w w w.  j a va  2 s  . c om

    //params = "format=json&";
    params = "method=foods.search&";
    params += "oauth_consumer_key=5f2d9f7c250c4d75b9807a4f969363a7&"; // ur consumer key 
    params += "oauth_nonce=123&";
    params += "oauth_signature_method=HMAC-SHA1&";
    Date date = new java.util.Date();
    Timestamp ts = new Timestamp(date.getTime());
    params += "oauth_timestamp=" + ts.getTime() + "&";
    params += "oauth_version=1.0&";
    params += "search_expression=" + foodName;

    String params2 = URLEncoder.encode(params);
    base += params2;
    System.out.println(base);
    String line = "";

    String secret = "76172de2330a4e55b90cbd2eb44f8c63&";
    Mac sha256_HMAC = Mac.getInstance("HMACSHA1");
    SecretKeySpec secret_key = new SecretKeySpec(secret.getBytes(), "HMACSHA1");
    sha256_HMAC.init(secret_key);
    String hash = Base64.encodeBase64String(sha256_HMAC.doFinal(base.getBytes()));

    //$url = "http://platform.fatsecret.com/rest/server.api?".$params."&oauth_signature=".rawurlencode($sig); 

    String url = "http://platform.fatsecret.com/rest/server.api?" + params + "&oauth_signature="
            + URLEncoder.encode(hash);
    System.out.println(url);
    list = xParser.foodSearchParser(url);
    for (int i = 0; i < list.size(); i++) {
        listOfFoodList.add(getFood(list.get(i)));
    }

    return listOfFoodList;
}

From source file:fitmon.DietAPI.java

public ArrayList<Food> getFood(String foodID) throws ClientProtocolException, IOException,
        NoSuchAlgorithmException, InvalidKeyException, SAXException, ParserConfigurationException {
    HttpClient client = new DefaultHttpClient();
    HttpGet request = new HttpGet("http://platform.fatsecret.com/rest/server.api&"
            + "oauth_consumer_key=5f2d9f7c250c4d75b9807a4f969363a7&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1408230438&"
            + "oauth_nonce=abc&oauth_version=1.0&method=food.get&food_id=33691");
    HttpResponse response = client.execute(request);
    BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

    String base = URLEncoder.encode("GET") + "&";
    base += "http%3A%2F%2Fplatform.fatsecret.com%2Frest%2Fserver.api&";

    String params;/*from   w ww. ja v  a  2 s.  com*/

    params = "food_id=" + foodID + "&";
    params += "method=food.get&";
    params += "oauth_consumer_key=5f2d9f7c250c4d75b9807a4f969363a7&"; // ur consumer key 
    params += "oauth_nonce=123&";
    params += "oauth_signature_method=HMAC-SHA1&";
    Date date = new java.util.Date();
    Timestamp ts = new Timestamp(date.getTime());
    params += "oauth_timestamp=" + ts.getTime() + "&";
    params += "oauth_version=1.0";
    //params += "search_expression=apple"; 

    String params2 = URLEncoder.encode(params);
    base += params2;
    System.out.println(base);
    String line = "";

    String secret = "76172de2330a4e55b90cbd2eb44f8c63&";
    Mac sha256_HMAC = Mac.getInstance("HMACSHA1");
    SecretKeySpec secret_key = new SecretKeySpec(secret.getBytes(), "HMACSHA1");
    sha256_HMAC.init(secret_key);
    String hash = Base64.encodeBase64String(sha256_HMAC.doFinal(base.getBytes()));

    //$url = "http://platform.fatsecret.com/rest/server.api?".$params."&oauth_signature=".rawurlencode($sig); 

    String url = "http://platform.fatsecret.com/rest/server.api?" + params + "&oauth_signature="
            + URLEncoder.encode(hash);
    System.out.println(url);
    xmlParser xParser = new xmlParser();
    ArrayList<Food> foodList = xParser.Parser(url);
    return foodList;
    //while ((line = rd.readLine()) != null) {
    //  System.out.println(line);
    //}
}

From source file:com.github.dozermapper.core.converters.DateConverter.java

public Object convert(Class destClass, Object srcObj) {
    final Class srcFieldClass = srcObj.getClass();

    long time;//from  w  w w .  j ava 2s  .  c  o  m
    int nanos = 0;
    if (Calendar.class.isAssignableFrom(srcFieldClass)) {
        Calendar inVal = (Calendar) srcObj;
        time = inVal.getTime().getTime();
    } else if (Timestamp.class.isAssignableFrom(srcFieldClass)) {
        Timestamp timestamp = (Timestamp) srcObj;
        time = timestamp.getTime();
        nanos = timestamp.getNanos();
    } else if (java.util.Date.class.isAssignableFrom(srcFieldClass)) {
        time = ((java.util.Date) srcObj).getTime();
    } else if (XMLGregorianCalendar.class.isAssignableFrom(srcFieldClass)) {
        time = ((XMLGregorianCalendar) srcObj).toGregorianCalendar().getTimeInMillis();
    } else if (dateFormat != null && String.class.isAssignableFrom(srcObj.getClass())) {
        try {
            if ("".equals(srcObj)) {
                return null;
            }
            time = dateFormat.parse((String) srcObj).getTime();
        } catch (ParseException e) {
            throw new ConversionException("Unable to parse source object using specified date format", e);
        }
        // Default conversion
    } else {
        try {
            time = Long.parseLong(srcObj.toString());
        } catch (NumberFormatException e) {
            throw new ConversionException("Unable to determine time in millis of source object", e);
        }
    }

    try {
        if (Calendar.class.isAssignableFrom(destClass)) {
            Constructor constructor = destClass.getConstructor();
            Calendar result = (Calendar) constructor.newInstance();
            result.setTimeInMillis(time);
            return result;
        }

        if (dateFormat != null && String.class.isAssignableFrom(destClass)) {
            return dateFormat.format(new java.util.Date(time));
        }

        Constructor constructor = destClass.getConstructor(Long.TYPE);
        Object result = constructor.newInstance(time);
        if (nanos != 0 && (Timestamp.class.isAssignableFrom(destClass))) {
            ((Timestamp) result).setNanos(nanos);
        }
        return result;
    } catch (Exception e) {
        throw new ConversionException(e);
    }
}

From source file:com.wabacus.system.datatype.TimestampType.java

public Object getColumnValue(ResultSet rs, String column, AbsDatabaseType dbtype) throws SQLException {
    java.sql.Timestamp ts = rs.getTimestamp(column);
    if (ts == null)
        return null;
    return new Date(ts.getTime());
}