1 , System Current time
Long SysTime =system.currenttimemillis (); Gets the current time of the system in milliseconds
datemydate = new Date ();// Get current Time
2. The java.util.Date type converts to a long type of seconds
java.util.Date dt = Newdate ();
Long sysTime = Dt.gettime ()/1000; //get the number of seconds, DateType of gettime () returns the number of milliseconds
3. Convert from long to date type
SimpleDateFormat sdf= newsimpledateformat ("mm/dd/yyyy HH:mm:ss");
//if it's a second, take the firstGets the number of milliseconds, if the millisecond is used directly, and then into the java.util.Date type
Java.util.Date dt = new Date (sysTime * 1000);
String Sdatetime = sdf.format (DT); //get a precise representation of the second: 08/31/2006 21:08:00
3 , String conversion java.util.Date type
String sDt = "08/31/2006 21:08:00";
SimpleDateFormat sdf= New SimpleDateFormat ("mm/dd/yyyy HH:mm:ss");
Date DT2 = Sdf.parse (sDt);
4 , date dates to strings string
Turn today's date into a string
SimpleDateFormat sdf= Newsimpledateformat ("mm/dd/yyyy HH:mm:ss");
String Datestr=sdf.format (New Date ());
5 , reference
// note that the HH and hh meanings are different, hh means to take 24-hour production, hh means to take 12-hour production
The meaning of the commonly used format, excerptedfrom the JDK, note that the meaning of the case is usually different:
Letters meaning Example
Y year 1996;96which year
M Month in year J uly; Jul;07which month of the year
M Minute Inhourthe first few minutes in one hours
W Week inyearthe first few weeks of the year
W Week inmonth 2the first few weeks of the one months
D Day Inyear 189the day ordinal of a year
D Day Inmonththe day of the one month
H Hour in Day (0-23) 0the first hours of the day ( -hour system)
H Hour in am/pm (1-12)the first hours of the morning and afternoon of the day ( Ahour system)
S Millisecond 978Number of milliseconds
s Second inminutethe first few seconds of a minute
A good memory is better than a bad pen. 2-java Date Type and conversion