java-date-handling-examples

How to print the current date and time

Posted On
Posted By admin

In this blog post, I will be demonstrating how you can print the current date and time.

 

Consider the following code snippet:


import java.util.Calendar;

public class PrintCurrentDateTimeDemo {

public static void main(String[] args) {
Date date = new Date();
System.out.println("Current date and time is "+date);

}

}

 

Here, we are using a java.util.Date instance.   This represents a particular instance in time. When we create a new Date object with the default constructor, it creates a Date object with the current date and time. The Sysout statement then prints the Date and time in this date object.

So this code prints the following output:

Current date and time is Mon Feb 25 09:31:36 IST 2019

 

 

If you like this post, please do let me know via the comments box below.  You can also connect with me via my Facebook Page or subscribe to my Youtube channel!

Related Post

leave a Comment