Java datetime date type, long type, conversion of string type representation
1. Convert java.util.Date type to long type
Java.util.Date dt = new Date ();
System.out.println (Dt.tostring ()); The meaning of Java.util.Date
Long lSysTime1 = Dt.gettime ()/1000; Gets the number of seconds, the date type of gettime () returns the number of milliseconds
2. Convert from long to date type
SimpleDateFormat sdf= New SimpleDateFormat ("mm/dd/yyyy HH:mm:ss");
The previous lsystime is the number of seconds, multiplying by 1000 to get the number of milliseconds, and then to the Java.util.Date type
Java.util.Date dt = new Date (LSYSTIME1 * 1000);
String sdatetime = sdf.format (DT); Get a precise representation of the second: 08/31/2006 21:08:00
System.out.println (Sdatetime);
3. "08/31/2006 21:08:00" format 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);
Continue conversion to get the number of seconds of the long type
Long ltime = Dt2.gettime ()/1000;
Note that HH and HH are different, hh means to take 24-hour production, hh means to take 12-hour production
The meaning of the commonly used format, excerpted from the JDK, note that the meaning of the case is usually different:
Example of letter meaning
Y years 1996;96 which year
M Month in year J uly; jul;07 which month of the year
M Minute in hour 301 hours of the first minute
W Week in the first few weeks of year 271
W Week in month the first few weeks of 21 months
Day of the year 1891
Days in month of 101 months
H Hour in Day (0-23) hours in 1 days (24-hour system)
H Hour in am/pm (1-12) hours of the morning and afternoon of 121 days (12-hour clock)
S millisecond of 978 milliseconds
S Second in minute 551 minutes of the first few seconds
4, the current time of the system
Long lSysTime2 = System.currenttimemillis (); Gets the current time of the system in milliseconds
Original: http://www.blogjava.net/algz/articles/324727.html
Java datetime date type, long type, string representation conversion (RPM)