How to convert sql.Timestamp in the formate MM/dd/yyyy hh:mm:ss.S to sql.timestamp with the formate MM/dd/yyyy 00.00.00.0

Basically i am trying to round of the timstamp just to take the date

有帮助吗?

解决方案

It depends on local timezone, you need Calendar

    Timestamp t = ...
    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(t.getTime());
    c.set(Calendar.HOUR_OF_DAY, 0);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);
    t = new Timestamp(c.getTimeInMillis());
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top