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. javascript - 關(guān)于css絕對定位在ios瀏覽器被橡皮筋遮擋的問題2. python - beautifulsoup獲取網(wǎng)頁內(nèi)容的問題3. python - 能通過CAN控制一部普通的家用轎車嗎?4. mysql優(yōu)化 - 關(guān)于mysql分區(qū)5. javascript - react input file6. 人工智能 - python 機(jī)器學(xué)習(xí) 醫(yī)療數(shù)據(jù) 怎么學(xué)7. centos7 編譯安裝 Python 3.5.1 失敗8. mysql - 分庫分表、分區(qū)、讀寫分離 這些都是用在什么場景下 ,會帶來哪些效率或者其他方面的好處9. html5 - 只用CSS如何實現(xiàn)input框的寬度隨框里輸入的內(nèi)容長短自動適應(yīng)?10. c++ - 請問MySQL_Connection::isReadOnly 怎么解決?
