Вопрос

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