文章详情页
java - 显示的时间能不能去掉毫秒
浏览:290日期:2023-10-26 13:24:13
问题描述

数据库里面的时间是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
相关文章:
1. dockerfile - 为什么docker容器启动不了?2. android - WebView加载天猫等购物网页出问题?3. 垃圾回收 - java 如何手动回收对象4. nignx - docker内nginx 80端口被占用5. javascript - vue错误提示 Cannot read property ’beforeRouteEnter’ of undefined6. 利用css3 translate来代替传统的修改left和top实现动画,触发webkit的GPU加速渲染功能实现流畅的动画效果7. javascript - typescript关于接口,对象字面量额外属性检测问题,为什么使用断言或者变量时就不会检测额外属性?8. javascript - 手淘国际版预先加载的html是如何实现的?9. css3:flex排版问题10. css - 有没有办法自定义 border 为 dashed 时的虚线间距?
排行榜

网公网安备