adsense


Showing posts with label JAVA EXAMPLES ROLL THROUGH HOURS & MONTHS. Show all posts
Showing posts with label JAVA EXAMPLES ROLL THROUGH HOURS & MONTHS. Show all posts

Sunday, 25 October 2015

JAVA EXAMPLES ROLL THROUGH HOURS & MONTHS PAGE 70

COMPUTER LANGUAGES HTML,C,C++.JAVA,.NET AND MULTIMEDIA basics and programs click home button



JAVA EXAMPLES ROLL THROUGH HOURS & MONTHS




Java Examples - Roll through hours & months



Problem Description:
How to roll through hours & months?
Solution:
This example shows us how to roll through monrhs (without changing year) or hrs(without changing month or year) using roll() method of Class calender.
import java.util.*;

public class Main {
   public static void main(String[] args) throws Exception {
      Date d1 = new Date();
      Calendar cl = Calendar. getInstance();
      cl.setTime(d1);
      System.out.println("today is "+ d1.toString());
      cl. roll(Calendar.MONTH, 100);
      System.out.println("date after a month will be " 
	  + cl.getTime().toString() );
      cl. roll(Calendar.HOUR, 70);
      System.out.println("date after 7 hrs will be "
      + cl.getTime().toString() );
   }
}
Result:
The above code sample will produce the following result.
today is Mon Jun 22 02:44:36 IST 2009
date after a month will be Thu Oct 22 02:44:36 IST 2009
date after 7 hrs will be Thu Oct 22 00:44:36 IST 2009