Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Timestamp comes with .0 at the end

I'm trying to put in some time stamps in a AnnotatedTimeLine (Google Chart), and its req. to be in the Datetime format. When I reformat (to Timestamp format) the string that I receive from the class, it gives me this:

2013-06-28 10:08:35.0

What I want to do is to remove the .0 at the end. How can I do this? The code looks like this:

    public List<Survey> getAllSurvey(List<Status> statusList) {
    String sqlValues = "SELECT * FROM status WHERE idCategory = (SELECT idCategory FROM category WHERE name = '"
            + statusList.get(0).getCategoryName() + "');";
    List<Survey> survies = new ArrayList<Survey>();
    try {
        List<Map<String, Object>> rows = getJdbcTemplate().queryForList(
                sqlValues);
        for (Map row : rows) {
            Survey survey = new Survey();
            survey.setCategoryName(statusList.get(0).getCategoryName());
            survey.setValue((String) (row.get("value")));
            survey.setUnit((String) row.get("unit"));
            survey.setTimestamp(row.get("timeStamp") + "");
            survies.add(survey);
            System.out.println(survey.toString());
        }
    } catch (BadSqlGrammarException e) {
        e.printStackTrace();
    } catch (Exception e) {
        System.out.println(sqlValues);
        e.printStackTrace();
    }
    return survies;
}

Thanks in advance!

like image 335
benskiiii Avatar asked Oct 04 '22 14:10

benskiiii


1 Answers

You must convert the timestamp to the dateformat you want in your class. The default string representation of Timestamp is including the nanoseconds at the end. If you want to change that you can always do this:

    Timestamp t = Your timestamp;
    SimpleDateFormat df = new SimpleDateFormat("YYYY.MM.dd HH:mm:ss");
    String s = df.format(t);
like image 172
Devolus Avatar answered Oct 07 '22 19:10

Devolus