文章详情页
java - 显示的时间能不能去掉毫秒
浏览:322日期: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. python小白 问关于类里面属性的问题2. javascript - switch...case...3. 怎么用navicat for mysql连接别的电脑的数据库?4. javascript - JS 里面的 delete object.key 到底删除了什么?5. 前端 - 在webstrom上pull代码时出现错误?6. css3 - 没明白盒子的height随width的变化这段css是怎样实现的?7. javascript - 有什么兼容性比较好的办法来判断浏览器窗口的类型?8. python - 怎样在linux下开发flask web应用时查看代码出错(traceback)的地方。9. mysql group by多个字段10. node.js - win10如何安装并使用babel?
排行榜

网公网安备