Question

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

Était-ce utile?

La solution

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());
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top