Opening Hours :7AM to 9PM
It is a predefined class in java.util package.it is used to get date and time along with other internal time and date properties of Calendar.
The main difference between date and Calendar class is date always represents current system date and time. Where as Calendar class can be used to get the date ,time and other properties in a complete Calendar year(from january to december).
Syntax:
Calendar c=Calendar.getInstance();
In the above syntax getInstance() is a predefined method of a Calendar class.Which returns Calendar class object.
import java.util.*;
public class Main {
public static void main(String[] args) {
Calendar c1=Calendar.getInstance();
System.out.println("Current date");
int dd=c1.get(Calendar.DATE);
int mm=c1.get(Calendar.MONTH);
mm++;
int yy=c1.get(Calendar.YEAR);
System.out.println(dd+"-"+mm+"-"+yy);
System.out.println("Current Time");
int h=c1.get(Calendar.HOUR);
int m=c1.get(Calendar.MINUTE);
int s=c1.get(Calendar.SECOND);
System.out.println(h+":"+m+":"+s);
int x=c1.get(Calendar.AM_PM);
if(x==0)
{
System.out.println("AM");
System.out.println("Good Morning");
}
else
{
System.out.println("PM");
System.out.println("Good Evening");
}
int dw=c1.get(Calendar.DAY_OF_YEAR);
System.out.println(dw);
}
}
import java.util.*;
public class Main {
public static void main(String[] args) {
Calendar c1=Calendar.getInstance();
System.out.println("Current date");
int dd=c1.get(Calendar.DATE);
int mm=c1.get(Calendar.MONTH);
mm++;
int yy=c1.get(Calendar.YEAR);
System.out.println(dd+"-"+mm+"-"+yy);
System.out.println("Current Time");
int h=c1.get(Calendar.HOUR);
int m=c1.get(Calendar.MINUTE);
int s=c1.get(Calendar.SECOND);
System.out.println(h+":"+m+":"+s);
int x=c1.get(Calendar.AM_PM);
int p,q,r;
Scanner ss=new Scanner(System.in);
if(dd==28 && mm==9 && yy==2022 && h>12 && m>10 && s>0)
{
System.out.println("Enter p,q values");
p=ss.nextInt();
q=ss.nextInt();
r=p+q;
}
else
{
System.out.println("Please execute some other time");
}
}
}