The following are typical classes used when dealing with date types in Java programming. ― java.util.Date; ― java.text.DateFormat; ― java.text.SimpleDateFormat;
When retrieving using the Date class, you can get the Date object with the current date and time by creating a Date object with no arguments. If you want to format the output format to any format, use SimpleDateFormat class etc.
Date date=new Date(); DateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm"); String formattedDate=dateFormat.format(date); System.out.println(formattedDate);
result:
Recommended Posts