首页  >  问答  >  正文

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

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

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

能不能去掉啊好难看

仅有的幸福仅有的幸福2675 天前903

全部回复(2)我来回复

  • 大家讲道理

    大家讲道理2017-06-23 09:16:23

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

    String str = timestamp.toString();
    str = str.substring(0, str.length() - 4);

    回复
    0
  • 代言

    代言2017-06-23 09:16:23

    使用SimpleDateFormatTimestamp转为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;
    }

    回复
    0
  • 取消回复