Java Calendar add subtract minutes

Description

Java Calendar add subtract minutes

import java.util.Calendar;
 
public class Main {
 
  public static void main(String[] args) {
   /*from   ww  w . ja v a  2 s.  c o  m*/
    Calendar now = Calendar.getInstance();
   
    System.out.println("Current time : " + now.getTime());
                     
    //add minutes to current date using Calendar.add method
    now.add(Calendar.MINUTE,20);
 
    System.out.println("Current time : " + now.getTime());
 
    //subtract minutes using Calendar.add method
    now = Calendar.getInstance();
    now.add(Calendar.MINUTE, -150);
 
    System.out.println("Current time : " + now.getTime());
   
  }
}



PreviousNext

Related