文章詳情頁
java - 顯示的時間能不能去掉毫秒
瀏覽:108日期: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. thinkPHP5中獲取數據庫數據后默認選中下拉框的值,傳遞到后臺消失不見。有圖有代碼,希望有人幫忙3. linux運維 - python遠程控制windows如何實現4. Python2中code.co_kwonlyargcount的等效寫法5. javascript - 如何用最快的速度C#或Python開發一個桌面應用程序來訪問我的網站?6. django - Python error: [Errno 99] Cannot assign requested address7. mysql數據庫做關聯一般用id還是用戶名8. [python2]local variable referenced before assignment問題9. 求救一下,用新版的phpstudy,數據庫過段時間會消失是什么情況?10. python小白,關于函數問題
排行榜
