您的位置:首页技术文章
文章详情页

java - 显示的时间能不能去掉毫秒

浏览:73日期:2023-10-26 13:24:13

问题描述

java - 显示的时间能不能去掉毫秒

数据库里面的时间是DateTime类型的获取时间

public Timestamp getDatetime() {return new Timestamp(System.currentTimeMillis()); }

能不能去掉啊好难看

问题解答

回答1:

看起来应该是在 Timestamp 转 String 的时候,直接调用了 Timestamp 的 toString 方法。最简单的办法就是你找到显示的地方,将 String str = timestamp.toString() 类似的代码改为

String str = timestamp.toString();str = str.substring(0, str.length() - 4);回答2:

使用SimpleDateFormat将Timestamp转为String类型。

public Timestamp getDatetime() { SimpleDateFormat df = new SimpleDateFormat('yyyy-MM-dd HH:mm:ss'); Timestamp now = new Timestamp(System.currentTimeMillis()); String str = df.format(now);return str;}

标签: java
相关文章: