【记坑】Oracle数据库Date类型查询结果多出".0"的解决方法

oracle设置数据库某张表的字段类型为date,数据库存值为 2019-11-25 18:51:47 格式,但是从数据库查询出来之后格式为  

String stopTime = map.get("stopTime").toString;

2019-11-25 18:51:47.0 ,多了个零,不知是毫秒还是纳秒,目前还不知为何,解决办法为转换时间类型或者前端分割字符串

1.格式化时间

String stopTime = map.get("stopTime").toString();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String date = sdf.format(sdf.parse(stopTime));

2.分割字符串

String stopTime = map.get("stopTime").toString();
String currentTime = stopTime.substring(0,19);
System.out.println(currentTime);

3.实体层替换

如果使用到了实体类,可以直接在get方法里直接替换掉

public String getStopTime() {
  String stopTime=this.stopTime.replace(".0","");
  return stopTime;
}

 

posted @ 2019-11-25 19:22  木马不是马  阅读(2400)  评论(0编辑  收藏  举报