您的位置:首頁技術文章
文章詳情頁

java - 顯示的時間能不能去掉毫秒

瀏覽:102日期: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
相關文章:
国产综合久久一区二区三区