In Java Date you can use the now() method of the java.time.LocalDate class to display the current date:
Example: 
import java.time.LocalDate; // The LocalDate class should be imported
public class Main {
public static void main(String[] args) {
LocalDate myobj=LocalDate.now(); // A date object is created
System.out.println("Today's Date: "+myobj); // Shows the date of the current day
}
}
Execute example and we will get the following result:
We can also obtain a date of any day with similar pattern by providing the year,month and day of month:
Example: 
import java.time.LocalDate; // The LocalDate class should be imported
public class Main {
public static void main(String[] args) {
LocalDate myobj=LocalDate.of(2005,6,30); // Shows date according to year , month and day of month
System.out.println(" Date: "+myobj); // Shows the date of the Specific day
}
}
Display Current Time In Java
Import the java.time.LocalTime class, and use its now() method to display the current time (hour, minute, second, and nanoseconds):
Example: 
import java.time.LocalTime; // The LocalTime class needs to be imported
public class Main {
public static void main(String[] args) {
LocalTime obj=LocalTime.now();
System.out.println("Current Time: "+obj);
}
}
We can also add and subtract (Hours, Minutes, Seconds , etc ) to the current time by using the commands:
plusHours()
plusMinutes()
Example: 
import java.time.LocalTime; // The LocalTime class needs to be imported
public class Main {
public static void main(String[] args) {
LocalTime obj=LocalTime.now();
System.out.println("Current Time: "+obj);
System.out.println("\nAfter Adding 5 hours and 40 minutes to the current time we get: ");
LocalTime obj2=obj.plusHours(5); // Adding 5 hours to the current times
LocalTime obj3=obj2.plusMinutes(40); // Adding 40 minutes to the new time (obj2)
System.out.println("\nNew Time : "+obj3);
}
}
Display Current Date and Time
Using the now() method of the java.time.LocalDateTime class, you can display the current date and time:
Example: 
import java.time.LocalDateTime; // The LocalDateTime class needs to be imported
public class Main{
public static void main(String[] args) {
LocalDateTime myObject=LocalDateTime.now();
System.out.println("Current Date and Time is: "+myObject);
}
}
We can also obtain the Local Time and date of any country by using the ZoneId class and by adding the continent name / country name while declaring the object of ZoneId.
Example: 
import java.time.LocalDateTime; // The LocalDateTime class needs to be imported
import java.time.ZoneId; // The Package for ZoneId is imported
public class Main{
public static void main(String[] args) {
ZoneId zoneid = ZoneId.of("Asia/Singapore"); // Object of ZoneId is created and the current time of singapore is obtained
LocalDateTime myObject=LocalDateTime.now(zoneid); // Using zoneid to obtain time zones of different countries
System.out.println("Current Date and Time in Singapore is: "+myObject);
}
}
Java Date and Time Format
Dates and times are separated in the example above by the letter “T” as shown in the above example. The DateTimeFormatter class in the same package provides the ofPattern() method for formatting and parsing date-time objects.
Here is an example that removes both the “T” and nanoseconds from the date and time.
The following examples formats the date into day – month number – year , and time into Hours : minutes : seconds pattern.
Example: 
import java.time.LocalDateTime; // The LocalDateTime class needs to be imported
import java.time.format.DateTimeFormatter; // The class for DataTimeFormatter is used
public class Main{
public static void main(String[] args) {
LocalDateTime my_object1=LocalDateTime.now();
System.out.println("Before Formatting Date and Time were displayed : "+my_object1);
DateTimeFormatter D_T_F=DateTimeFormatter.ofPattern("dd – MM – yyyy HH : mm : ss");
// New Date format = Day of Month – Month number – Year
// New Time format = Hours : Minutes : Seconds
String new_data_time=my_object1.format(D_T_F);
System.out.println("After formatting Data and Time are displayed as: "+new_data_time);
}
}
We can also change the format of date and time as per our preference as shown in the example below:
Example: 
import java.time.LocalDateTime; // The LocalDateTime class needs to be imported
import java.time.format.DateTimeFormatter; // The class for DataTimeFormatter is used
public class Main{
public static void main(String[] args) {
LocalDateTime my_object1=LocalDateTime.now();
System.out.println("Before Formatting Date and Time were displayed : "+my_object1);
DateTimeFormatter D_T_F=DateTimeFormatter.ofPattern("MM – dd – yyyy mm : HH : ss");
// Date format = Month – Day of Month – Year
// Time format = Minutes : Hours : Seconds
String new_data_time=my_object1.format(D_T_F);
System.out.println("After formatting Data and Time are displayed as: "+new_data_time);
}
}
Using the ofPattern() method, you can display the time and date in different formats. Here are some examples: