w3resource logo


Java Programming Exercies

Java DateTime, Calendar Exercises: Get current full date and time

Secondary Nav

Java DateTime, Calendar : Exercise-6 with Solution

Write a Java program to get current full date and time.

Java Code:

import java.util.*;
public class Exercise6 {
   public static void main(String[] args)
    {
   Calendar now = Calendar.getInstance();
    System.out.println();
    System.out.println("Current full date and time is : " + (now.get(Calendar.MONTH) + 1) + "-"
        + now.get(Calendar.DATE) + "-" + now.get(Calendar.YEAR) + " "
        + now.get(Calendar.HOUR_OF_DAY) + ":" + now.get(Calendar.MINUTE) + ":"
        + now.get(Calendar.SECOND) + "." + now.get(Calendar.MILLISECOND));
	System.out.println();
    }
}

Sample Output :

Current full date and time is : 9-15-2016 13:51:58.77 

Java Practice online:

import java.util.*;
public class Exercise6 {
   public static void main(String[] args)
    {
   Calendar now = Calendar.getInstance();
    System.out.println();
    System.out.println("Current full date and time is : " + (now.get(Calendar.MONTH) + 1) + "-"
        + now.get(Calendar.DATE) + "-" + now.get(Calendar.YEAR) + " "
        + now.get(Calendar.HOUR_OF_DAY) + ":" + now.get(Calendar.MINUTE) + ":"
        + now.get(Calendar.SECOND) + "." + now.get(Calendar.MILLISECOND));
	System.out.println();
    }
}



Join our Question Answer community to learn and share your programming knowledge.

Solve these problems:

Java: How to convert a string to an integer in Java?

C#: Loops in c#

SQL: JOIN using more than 5 tables