how to use Calender & Date classes in java?

1 Like

These classes are used to the retrieve the data and time. In an application and use them accordingly.

import java.util.*;

class Datedemo{

public static void main(String[] args){ //getInstance() is a factory Method

Calender c = Calender.getInstance();

int date = c.get(Calender.DATE);

int month = c.get(Calender.MONTH);

int year = c.get(Calender.YEAR);

System.out.println(β€œDate:” +date+ β€œ/” +(++month)+ ”/” +year);

int hour = c.get(Calender.Hour);

int minute = c.get(Calender.MINUTE);

int second = c.get(Calender.SECOND);

System.out.println(β€œTime =” +hour+ β€œ:” +minute+ β€œ:” +second);

Date d = new Date();

System.out.println(β€œDate:” + d);