Example of time difference calculation in Oracle:

Source: Internet
Author: User
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;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.