Timestamps are like 1377216000000 This format we often use in the MySQL database to convert time to timestamp or timestamp to date format, let me introduce the wirelessly timestamp operation conversion method.
First, the principle
The principle of time stamping is to convert the time format into decimal format, so that it is convenient to calculate the time. Good ~ go directly to the topic. (The following encapsulates a class, the need for students can refer to or direct copy can be used.) )
such as: August 23, 2013 after the conversion is 1377216000000
Second, step
1, create the DATEUTILSL class.
importjava.text.parseexception;importjava.text.simpledateformat;importjava.util.date; /** @author Msquirrel*/ Public classdateutils {privatesimpledateformat SF=NULL; /*gets the system time format as: "Yyyy/mm/dd"*/ Public StaticString getcurrentdate () {Date D=newdate (); SF= Newsimpledateformat ("yyyy mm month DD Day"); Returnsf.format (d); } /*time stamp converted into character channeling*/ Public StaticString getdatetostring (LongTime ) {Date D=newdate (time); SF= Newsimpledateformat ("yyyy mm month DD Day"); Returnsf.format (d); } /*Convert A string to a timestamp*/ Public Static Longgetstringtodate (String time) {SDF= Newsimpledateformat ("yyyy mm month DD Day"); Date Date=newdate (); Try{Date=Sdf.parse (time); } Catch(ParseException e) {//TODO auto-generated Catch blockE.printstacktrace (); } returndate.gettime (); }
2, in the corresponding use of the place to call on it.
// Get system Current time //timestamp converted to time format dateutils.getstringtodate (" time format " ); // time format converted to timestamp
Android time Stamp Simple conversion