Package
Import Java.sql.Timestamp;
Import Java.text.SimpleDateFormat;
Import Java.util.Date;
Import Org.junit.Test;
Timestamp timestamp and SimpleDateFormat conversion date format
@Test
public void Timestamptest () {
01: Date converted to string
Date date = new Date ();
Date.getdate () was awarded the 1970-01-01 08:00:00.011
Date.gettime () Gets the number of milliseconds from 1970-01-01 08:00:00.011 onwards to the present
Timestamp can convert the resulting number of milliseconds into the current system time
Timestamp Timestamp =null;//New Timestamp (Date.gettime ());
Output 2015-12-11 08:41:22.391, including number of milliseconds
System.out.println ("Number of milliseconds:" +date.gettime ());
The number of milliseconds after the removal time
Set the time format first
SimpleDateFormat format=new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");
System.currenttimemillis () and Date.gettime () are the same number of milliseconds obtained
Timestamp=new timestamp (System.currenttimemillis ());
Converts a formatted time to a string type
String Nowtime=format.format (timestamp);
System.out.println ("Converted time:" +nowtime);
02:string Convert to date
String Time=format.format (date);
System.out.println (time);
Timestamp=timestamp.valueof (time);
SYSTEM.OUT.PRINTLN (timestamp);
}
The original teacher's time conversion problem (slag-off day)