Java -Retrieve current date and time

April 2018


I need to display JFrame with labels and next to these labels, the date and time at which they were typed.
For this I need to retrieve and display the date and time in a JLabel but I can not even recover those below in a simple format such as: DD/MM/YYYY and HH/ MM/SS.


You must use the Date class from the java.util package
Inside, you have the Date () constructor which creates the current date. To obtain a more readable form you do a:

Date myDate = new Date();  
// Display:  

Thanks to maily for this tip.
Published by deri58. Latest update on September 20, 2012 at 10:27 AM by deri58.
This document, titled "Java -Retrieve current date and time," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (
Progress bar in C#
C++: A simple program to find the total of five values