Java Examples
Java ExamplesPrograms with output

Java program to Display Current date and time

import java.util.*;
class DateAndTime
   public static void main(String args[])
      int day, month, year;
      int second, minute, hour;
      GregorianCalendar date = new GregorianCalendar();
      day = date.get(Calendar.DAY_OF_MONTH);
      month = date.get(Calendar.MONTH);
      year = date.get(Calendar.YEAR);
      second = date.get(Calendar.SECOND);
      minute = date.get(Calendar.MINUTE);
      hour = date.get(Calendar.HOUR);
      System.out.println("Current date:  "+day+"/"+(month+1)+"/"+year);
      System.out.println("Current time:  "+hour+" : "+minute+" : "+second);
urrent date: 24-10-2022
Current time: 4:5:18

Share this page on:

Was this page helpful ?

Let us know how we did!

Subscribe Email Updates

to get latest update