文章詳情頁
java - 顯示的時間能不能去掉毫秒
瀏覽:157日期: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. javascript - ng-bind-html中 自定義的指令 不生效!2. css3中translate(-50%,-50%)對 transform-origin的奇葩影響?3. 隨機產生200個小寫英文字母,并統計個數,這是在網上看到的粒子,我想問怎樣把它變得更簡便?4. Echart X坐標軸名稱放在左邊與Y坐標抽刻度重疊,如何解決?5. objective-c - 使用axios 通過vuex mutation修改數據 getter第一次獲取失敗 第二次成功6. javascript - 為什么用JS設置a標簽的diplay無效,在CSS中卻有效?7. javascript - vue2.0中,$refs對象為什么用駝峰的方式獲取不到屬性?8. JQuery的目的在哪里?設置這些也可以通過css解決!9. css - .clearfix:after中為什么設置display: table10. vim - docker中新的ubuntu12.04鏡像,運行vi提示,找不到命名.
排行榜
