Home Java Java -Retrieve current date and time

Java -Retrieve current date and time

Issue

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.

Solution

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: Systemut.println(myDateoString());

Thanks to maily for this tip.

  • Java

LEAVE A REPLY

Please enter your comment!
Please enter your name!