时间戳结尾带有.0 [英] Timestamp comes with .0 at the end
本文介绍了时间戳结尾带有.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在AnnotatedTimeLine(Google图表)及其要求中添加一些时间戳.为Datetime格式.当我重新格式化(从时间戳格式)从类中收到的字符串时,它会给出以下信息:
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
2013-06-28 10:08:35.0
我想要做的是最后删除.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;
}
提前谢谢!
推荐答案
尝试这一行解决方案
survey.setTimestamp(row.get("timeStamp").toString().replaceAll("\\.\\d+", ""));
如果性能至关重要,那么此解决方案会更好
if performance is critical then this solution is better
String ts = row.get("timeStamp").toString();
ts = ts.substring(0, str.indexOf('.'));
这篇关于时间戳结尾带有.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文