java - 顯示的時間能不能去掉毫秒
問題描述
數(shù)據(jù)庫里面的時間是DateTime類型的獲取時間
public Timestamp getDatetime() {return new Timestamp(System.currentTimeMillis()); }
能不能去掉啊好難看
問題解答
回答1:看起來應(yīng)該是在 Timestamp 轉(zhuǎn) String 的時候,直接調(diào)用了 Timestamp 的 toString 方法。最簡單的辦法就是你找到顯示的地方,將 String str = timestamp.toString() 類似的代碼改為
String str = timestamp.toString();str = str.substring(0, str.length() - 4);回答2:
使用SimpleDateFormat將Timestamp轉(zhuǎn)為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;}
相關(guān)文章:
1. 怎么在phpstudy中用phpexcel上傳數(shù)據(jù)到MYSQL?2. javascript - 百度搜索網(wǎng)站,如何讓搜索結(jié)果顯示一張圖片加上一段描述,如圖;求教3. phpadmin的數(shù)據(jù)庫,可以設(shè)置自動變化時間的變量嗎?就是不需要接收時間數(shù)據(jù),自動變化4. html5和Flash對抗是什么情況?5. 求救一下,用新版的phpstudy,數(shù)據(jù)庫過段時間會消失是什么情況?6. javascript - win7 npm安裝gulp失敗,已是管理員打開,也設(shè)置了文件權(quán)限7. html - 爬蟲時出現(xiàn)“DNS lookup failed”,打開網(wǎng)頁卻沒問題,這是什么情況?8. boot2docker無法啟動9. mac里的docker如何命令行開啟呢?10. 這是什么情況???
