I need to make a time difference judgment, and I don't want to write it. So I found out from the previous code that MI has... let's record it now.
Public static void main (String [] args) throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat ("yyyy-MM-dd HH: mm: ss ");
Date currentTime = new Date ();
// Convert the intercepted time string into a Time Format String
Date beginTime = sdf. parse ("12:53:30 ");
// The default value is millisecond. Divide by 1000 to convert to seconds.
Long interval = (currentTime. getTime ()-beginTime. getTime ()/1000; // second
Long day = interval/(24*3600); // day
Long hour = interval % (24*3600)/3600; // hour
Long minute = interval % 3600/60; // minute
Long second = interval % 60; // second
System. out. println ("two time differences:" + day + "day" + hour + "hour" + minute + "minute" + second + "second ");
}
Author "xingcxb"