The format of the implementation date, the class needs to be used: Java.text.DateFormat
DateFormat does not have a constructor that can be used directly, typically using dateformate subclasses---java.text.SimpleDateFormat to complete the construct.
Public SimpleDateFormat (String pattern)
Test code
Copy Code code as follows:
Import Java.text.DateFormat;
Import Java.text.SimpleDateFormat;
Import Java.util.Date;
public class Dateformattest
{
public static void Main (string[] args)//Note: String do not write strings
{
DateFormat df = new SimpleDateFormat ("yyyy mm month DD Day Hh:mm:ss");
Date currenttime = new Date ();
String CURRENTTIMEDF = Df.format (currenttime);
System.out.println ("Current time is:" +CURRENTTIMEDF);
}
}
SimpleDateFormat has the following characteristics
1. Accept the corresponding format string and format the parts in date to display. Wherein, the YYYY represents the year, the MM represents the month, DD represents the day, and the HH represents the hour, mm represents the minute, and the SS represents the second
2, in the format string, in addition to the representative meaning of the part, the other parts appear as is.