Get Today’s Date

This code example shows how to output today’s date. It uses the Calendar class. Since it is an abstract class and therefore cannot be instantiated we created it using the getInstance() method. Then we create an instance of the SimpleDateFormat class which takes the format we want to display the date in as argument to the constructor.
Finally the method ‘format()’ is called on the SimpleDateFormat object. The format() method takes a java.util.Date object as argument and we can get our hands on one by calling the getTime() method of the Calendar instance.

The output from the code above prints the current date.


From Java 8 there’s a new date API. To get the current date in different formats with this new API check out the following link:

Display date in different formats with the LocalDate class

Search for more Java info on this site here:
Custom Search

Please type any questions here.