/**
* Calculate the time difference between two dates
* @ Param formattime1
* @ Param formattime2
* @ Return
*/
Public static string gettimedifference (timestamp formattime1, timestamp formattime2 ){
Simpledateformat timeformat = new simpledateformat ("yyyy-mm-dd, HH: mm: SS ");
Long T1 = 0l ;
Long T2 = 0l ;
Try {
T1 = timeformat. parse (gettimestampnumberformat (formattime1). gettime ();
} Catch (parseexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
}
Try {
T2 = timeformat. parse (gettimestampnumberformat (formattime2). gettime ();
} Catch (parseexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
}
// Because the t1-t2 gets the millisecond level, so the first 3600000 gets the hour. The same is true for days or seconds.
Int hours = (INT) (T1-T2)/3600000 );
Int minutes = (INT) (T1-T2)/1000-hours * 3600)/60 );
Int second = (INT) (T1-T2)/1000-hours * 3600-minutes * 60 );
Return "" + hours + "Hour" + minutes + "Minute" + second + "second ";
}
/**
* Formatting time
* Locale is used to set language-sensitive operations.
* @ Param formattime
* @ Return
*/
Public static string gettimestampnumberformat (timestamp formattime ){
Simpledateformat m_format = new simpledateformat ("yyyy-mm-dd, HH: mm: SS", new locale ("ZH", "cn "));
Return m_format.format (formattime );
}