文章详情页
java - 显示的时间能不能去掉毫秒
浏览:113日期: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. mysql - JAVA怎么实现一个DAO同时实现查询两个实体类的结果集2. sql语句 - 如何在mysql中批量添加用户?3. mysql建表报错,查手册看不懂,求解?4. PHP类属性声明?5. 求大神支招,php怎么操作在一个html文件的<head>标记内添加内容?6. 怎么php怎么通过数组显示sql查询结果呢,查询结果有多条,如图。7. 致命错误: Class ’appfacadeTest’ not found8. 老师们php,插入数据库mysql,都是空的,要怎么解决9. mysql - 数据库建字段,默认值空和empty string有什么区别 11010. phpstady在win10上运行
排行榜
