java - 顯示的時(shí)間能不能去掉毫秒
問題描述
數(shù)據(jù)庫(kù)里面的時(shí)間是DateTime類型的獲取時(shí)間
public Timestamp getDatetime() {return new Timestamp(System.currentTimeMillis()); }
能不能去掉啊好難看
問題解答
回答1:看起來應(yīng)該是在 Timestamp 轉(zhuǎn) String 的時(shí)候,直接調(diào)用了 Timestamp 的 toString 方法。最簡(jiǎn)單的辦法就是你找到顯示的地方,將 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. Span標(biāo)簽2. docker-machine添加一個(gè)已有的docker主機(jī)問題3. 關(guān)docker hub上有些鏡像的tag被標(biāo)記““This image has vulnerabilities””4. docker-compose中volumes的問題5. angular.js使用$resource服務(wù)把數(shù)據(jù)存入mongodb的問題。6. javascript - ng-options 設(shè)置默認(rèn)選項(xiàng),不是設(shè)置第一個(gè)哦,看清楚了!7. SessionNotFoundException:會(huì)話ID為null。調(diào)用quit()后使用WebDriver嗎?(硒)8. redis啟動(dòng)有問題?9. android新手一枚,android使用httclient獲取服務(wù)器端數(shù)據(jù)失敗,但是用java工程運(yùn)行就可以成功獲取。10. java - Collections類里的swap函數(shù),源碼為什么要新定義一個(gè)final的List型變量l指向傳入的list?
