Fri Sep 24 2021
Date Time
Java Programming825 views
File Name: date-time.java
/* Using GregorianCalendar */
import java.io.*;
import java.util.*;
class datetime {
public static void main(String args[ ]) {
String months[ ] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
/* GregorianCalendar to get current date and time of the local timezone */
GregorianCalendar cal = new GregorianCalendar();
System.out.println("Date: "+months[cal.get(Calendar.MONTH)]+" "+cal.get(Calendar.DATE)+" "+cal.get(Calendar.YEAR));
System.out.println("Time: "+cal.get(Calendar.HOUR)+":"+cal.get(Calendar.MINUTE)+":"+cal.get(Calendar.SECOND));
/* check the current year is leap year or not */
if(cal.isLeapYear(cal.get(Calendar.YEAR)))
System.out.println("Its a Leap Year!");
else
System.out.println("Its not a Leap Year!");
}
}
/* Output */
Date: Sep 25 2014
Time: 11:3:13
Its not a Leap Year!
Author:Geekboots