C Books Guide and List
C++ Books Guide and List
Best Java Books

3,749 questions

4,049 answers

114 comments

10,705 users

how to use Calender & Date classes in java?

+1 vote
4,333 views
asked by augustaina Sr Member (4,820 points)

1 Answer

0 votes
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);

          }

   }
answered by rock Expert (14,990 points)

Related questions

0 votes
1 answer 25 views
+1 vote
1 answer 57 views
0 votes
1 answer 18 views
18 views asked by sara Guru (24,570 points)
0 votes
1 answer 12 views
12 views asked by taye Sr Member (4,970 points)
0 votes
1 answer 29 views
29 views asked by john Guru (27,140 points)
...