文章詳情頁
java - 顯示的時間能不能去掉毫秒
瀏覽:127日期: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. docker images顯示的鏡像過多,狗眼被亮瞎了,怎么辦?2. Java:密碼包(加密和解密)。無效的密鑰錯誤3. css - 微信小程序點擊展開,再次點擊收回4. 點擊頁面就自動輸入到mysql.求解5. macos - mac下docker如何設置代理6. css - vue.js的vue單文件組件style中的scoped屬性無效7. angular.js - 在ng-option 里使用過濾器無效8. node.js - 求問nw.js開發桌面版,其js計算性能如何?9. 我在centos容器里安裝docker,也就是在容器里安裝容器,報錯了?10. thinkphp5.1學習時遇到session問題
排行榜
