Java - Can milliseconds be removed from the displayed time?
仅有的幸福
仅有的幸福 2017-06-23 09:14:23
0
2
951

The time in the database is of DateTime type
Getting the time

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

Can you remove it? It’s so ugly

仅有的幸福
仅有的幸福

reply all(2)
大家讲道理

It seems that when Timestamp is converted to String, the toString method of Timestamp is directly called.
The easiest way is to find the display place and change String str = timestamp.toString() similar code to

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

Use SimpleDateFormat to convert Timestamp to String type.

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;
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template