5:24 pm - Sunday October 22, 2017

Calendar in java example program computeTime()

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044
/**
@author: candidjava
@description: Calendar in JAVA example program for computeTime()
 */

import java.util.Calendar;
import java.util.GregorianCalendar;

public class CalendarDemo extends GregorianCalendar {
	public static void main(String[] args) {
		// create a new calendar
		CalendarDemo cal = new CalendarDemo();
		// print the current date
		System.out.println("The current date is : " + cal.getTime());
		// clear the calendar
		cal.clear();
		// set a new year and call computeFields()
		cal.set(GregorianCalendar.YEAR, 1998);
		cal.computeTime();
		// print the current date
		System.out.println("New date is : " + cal.getTime());
	}
}

Output:

The current date is : Fri Oct 12 19:04:46 PDT 2012
New Date is : Thu Jan 01 00:00:00 PST 1998

BACK

Filed in: Z-A All Java Codes

Comments are closed.