Java Date Time - Java Calendar.setTime(Date date)








Syntax

Calendar.setTime(Date date) has the following syntax.

public final void setTime(Date date)

Example

In the following code shows how to use Calendar.setTime(Date date) method.

/* w w w.ja va 2 s .c o  m*/


import java.util.Calendar;
import java.util.Date;

public class Main {

   public static void main(String[] args) {

      Calendar cal = Calendar.getInstance();

      // get the current time
      System.out.println("Current time is :" + cal.getTime());

      Date date = new Date();
      cal.setTime(date);
    
      // print the new time
      System.out.println("After setting Time:  " + cal.getTime());
   }
}

The code above generates the following result.