Today, when I was working on a project, I encountered the following problem: I want to get the online duration: I want to check the database through SQL statements, but I finally found that this solution still cannot be solved. Finally, I thought of another one: it is the get () method that calculates the time difference directly in the online time.
Today, when I was working on a project, I encountered the following problem: I want to get the online duration: I want to check the database through SQL statements, but I finally found that this solution still cannot be solved. Finally, I thought of another one: it is the get () method that calculates the time difference directly in the online time.
Today, when I was working on a project, I encountered the following problem: To get the online duration:
As follows:
I previously thought of a solution: I want to check the database through SQL statements, but I finally found that this solution still cannot be solved. Finally I thought of another one:
By calculating the time difference, you can assign a value to the get () method of the online duration, so that you can get the value easily.
If you don't talk much about it, go directly to the Code:
1. This is your calculation time difference class:
Public class DateFormat {
/**
* Calculate the time difference between the two time points.
* @ Param from
* @ Param
* @ Return
*/
Public static String timeBetweens (Date from, Date ){
Final long ONEDAY = 86400000L; // 1 day = 86400000 milliseconds
Final long ONEHOUR = 3600000L; // 1 hour = 3600000 milliseconds
Final long ONEMIN = 60000L; // 1 minute = 60000 milliseconds
Long days = 0, hours = 0, mins = 0, secs = 0;
If (to. after (from )){
Secs = to. getTime ()-from. getTime ();
Days = secs/ONEDAY;
Secs = secs % ONEDAY;
Hours = secs/ONEHOUR;
Secs = secs % ONEHOUR;
Mins = secs/ONEMIN;
}
String rtnStr = days + "day" + hours + "Hour" + mins + "Minute ";
Return rtnStr;
}
Public static void main (String [] args ){
Date date = new Date ();
Date date1 = new Date ();
String string = timeBetweens (date, date1 );
System. out. println (string );
}
}
2. This is your entity class:
Private String wmistiming;
Public String getWmistiming (){
Return DateFormat. timeBetweens (wlogdate, wupdate );
}
Public void setWmistiming (String wmistiming ){
This. wmistiming = wmistiming;
}