Import Java. text. parseposition; import Java. text. simpledateformat; import Java. util. date; public class intervalutil {Public String getinterval (string createtime) {// The input time format must be similar to the format string interval = NULL such as 17:53:20; simpledateformat SD = new simpledateformat ("yyyy-mm-dd hh: mm: SS"); parseposition Pos = new parseposition (0); Date d1 = (date) SD. parse (createtime, POS); // use the current time interval from January 1, 1970 to new date (). gettime () minus the time interval from January 1, 1970 d1.gettime (), it is obtained that the time interval between the previous time and the current time is long time = new date (). gettime ()-d1.gettime (); // The time interval obtained is millisecond if (Time/1000 <10 & time/1000> = 0) {// If the interval is less than 10 seconds, the system displays the time interval "just" Time/10 ". The unit of the time interval is second interval =" just ";} else if (Time/3600000 <24 & time/3600000> = 0) {// The number of hours before which int H = (INT) is displayed if the time interval is less than 24 hours) (Time/3600000); // The unit of the obtained time interval is hour interval = H + "before Hour ";} else if (Time/60000 <60 & time/60000> 0) {// if the time interval is less than 60 minutes, the number of minutes before int M = (INT) is displayed) (time % 3600000)/60000); // The unit of the obtained time interval is minute interval = m + "Minutes Ago ";} else if (Time/1000 <60 & time/1000> 0) {// if the time interval is less than 60 seconds, the number of seconds before the display int Se = (INT) (time % 60000)/1000); interval = Se + "seconds ago";} else {// greater than 24 hours, the normal time is displayed, however, the second simpledateformat SDF = new simpledateformat ("yyyy-mm-dd hh: mm"); parseposition pos2 = new parseposition (0); Date D2 = (date) SDF is not displayed. parse (createtime, pos2); interval = SDF. format (D2) ;}return interval ;}}