- Instant help with your Java coding problems

Get actual date in Java

Question:
How to get actual date in Java?
Answer:
Date today = new Date();

// In string format
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String todayStr = formatter.format(new Date());
Description:

In Java, you can get the actual date by simply creating a new Date object. If you want to get a nicely formatted string representation of the date, use the SimpleDateFormat class with the appropriate format string.

Reference:
Java Date reference
Share "How to get actual date in Java?"