API--- java. util . Date: Date class, month from 0-11;
The conversion between the date object and the millisecond value.
1, the Date object turns into a millisecond value. the getTime method in the Date class .
2, how to turn the obtained millisecond value into a specific date?
The SetTime method in the Date class . You can also pass a constructor.
Date object turns into millisecond value
Date d = new Date ();
Long time1 = D.gettime ();
Long time2 = System.currenttimemillis (); // millisecond value.
millisecond value turns into a specific date
Long time = 1322709921312l;
Date d = new Date ();
D.settime (time);
Convert a date string into a Date object : Using the dateformat method. Date Parse (String source) ;
public static void Method () throws Exception {
String str_time = "2016/12/03";
DateFormat df = new SimpleDateFormat ("Yyyy/mm/dd"); //simpledateformat is formatted as a user-definable format that can be specified.
Date d = df.parse (Str_time);
}
If you don't need to use a specific formatting style, you can fully use The static Factory method in the DateFormat class gets the specific object that has been wrapped in style.
Getdateinstance (); Getdatetimeinstance ();
Date d = new Date ();
DateFormat df = dateformat.getdateinstance (Dateformat.long);
DF = dateformat.getdatetimeinstance (Dateformat.long,dateformat.long);
String str_time = Df.format (d);
How to convert a Date object to a string: the format method in the DateFormat class .
// Create date Format object.
DateFormat df = new SimpleDateFormat (); // The creation of the object encapsulates a default date format. 16-12-3 pm 1:48
If you want to customize the date format. You can use the SimpleDateFormat constructor. The specific format is passed into the constructor as a parameter. How to represent the middle-aged part of the day? You can have to participate in the Format object document.
DF = new SimpleDateFormat ("yyyy MM month dd Day HH:mm:ss");
call the format method in DateFormat. Formats an existing Date object.
String str_time = Df.format (d);
Date: Date