Home Tutorial Java Core Java add minutes to Date

 
 

Java add minutes to Date
Posted on: October 11, 2012 at 12:00 AM
In this tutorial, you will learn how to add minutes to date.

Java add minutes to Date

In this tutorial, you will learn how to add minutes to date.

Java Calendar class is a very useful and handy class. It is basically used in date time manipulation. Here, we are going to add few minutes to current date and return the resultant time. For this, we have created a calendar instance and get a date to represent the current date. Then using the method add() of Calendar class, we have added 56 minutes to the calendar which in result display the resulted time.

Example:

import java.util.*;
import java.text.*;

public class AddMinutesToDate{

  public static void main(String[] args){
    Calendar calendar = Calendar.getInstance();
    Date today = calendar.getTime();
	SimpleDateFormat sdf=new SimpleDateFormat("hh:mm:ss");
    System.out.println("Current Time: " + sdf.format(today));
    calendar.add(Calendar.MINUTE, 56);
    Date addMinutes = calendar.getTime();
    System.out.println("Time after 56 minutes: " + sdf.format(addMinutes));
  }
}

Output:

Current Time: 12:30:32
Time after 4 hours: 01:26:32

Related Tags for Java add minutes to Date:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.