Java Data Type How to - Round date to day


We would like to know how to round date to day.


//from   w  w  w.  j av  a  m
import java.util.Calendar;
import java.util.Date;

public class Main {

  public static void main(String[] args) {
    System.out.println(round2Day(new Date()));

  public static Date round2Day(Date date) {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return cal.getTime();

The code above generates the following result.