文章詳情頁
java - 顯示的時間能不能去掉毫秒
瀏覽:118日期: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 - linux怎么在每天的凌晨2點執行一次這個log.py文件2. 關于mysql聯合查詢一對多的顯示結果問題3. 實現bing搜索工具urlAPI提交4. MySQL主鍵沖突時的更新操作和替換操作在功能上有什么差別(如圖)5. 數據庫 - Mysql的存儲過程真的是個坑!求助下面的存儲過程哪里錯啦,實在是找不到哪里的問題了。6. windows誤人子弟啊7. 冒昧問一下,我這php代碼哪里出錯了???8. 如何用筆記本上的apache做微信開發的服務器9. 我在網址中輸入localhost/abc.php顯示的是not found是為什么呢?10. mysql優化 - MySQL如何為配置表建立索引?
排行榜
