Date Time Java Program

Date time java program is one of the common, rather classic program.

In general date time program is written and executed in many programming languages.

Here in this post we will learn how to print or display current system date and time in java.

In this program we will be using class GregorianCalendar of java.util package. Let’s get into example,

Example: Date Time Java Program

Date Time Java Program

Also Read – Convert Date To String Java Program

import java.util.*;

public class Date_Time {

public static void main(String[] args) {

int year, month, day;
int hour, minute, second;
GregorianCalendar dt = new GregorianCalendar();

year = dt.get(Calendar.YEAR);
month = dt.get(Calendar.MONTH);
day = dt.get(Calendar.DAY_OF_MONTH);

hour = dt.get(Calendar.HOUR);
minute = dt.get(Calendar.MINUTE);
second = dt.get(Calendar.SECOND);

System.out.println("Current date is " + day + "/" + (month + 1) + "/" + year);
System.out.println("Current time is " + hour + ":" + minute + ":" + second);



Current date is 29/12/2016
Current time is 7:28:17

About the author


View all posts

Leave a Reply

Your email address will not be published. Required fields are marked *