java - 顯示的時間能不能去掉毫秒
仅有的幸福
仅有的幸福 2017-06-23 09:14:23
0
2
878

#資料庫裡面的時間是DateTime類型的
取得時間

public Timestamp getDatetime() {
        return new Timestamp(System.currentTimeMillis());
    }

能不能去掉啊好難看

仅有的幸福
仅有的幸福

全部回覆(2)
大家讲道理

看起來應該是在 TimestampString 的時候,直接呼叫了 TimestamptoString 方法。
最簡單的方法就是你找到顯示的地方,將 String str = timestamp.toString() 類似的程式碼改為

String str = timestamp.toString();
str = str.substring(0, str.length() - 4);
代言

使用SimpleDateFormatTimestamp轉為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;
}
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!