Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9180459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:03:39+00:00 2026-06-17T18:03:39+00:00

I have a search button, when the user clicks the search button the search()

  • 0

I have a search button, when the user clicks the search button the search() method is get called. I need to calculate the how much time it took to display the result to the user as we see in the google search.

This is my code.

        SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String strDate;
def startTime() { 
    Calendar cal = Calendar.getInstance();
    System.out.println("Current milliseconds since 13 Oct, 2008 are :"
    + cal.getTimeInMillis());
    long startTime=cal.getTimeInMillis();
    /*Date startNow = new Date();
    strDate = sdfDate.format(startNow);
    Date startTime=sdfDate.parse(strDate);
    print "startTime"+startTime*/
    return  startTime;

}
def endTime(){
    Calendar cal = Calendar.getInstance();
    System.out.println("Current milliseconds  :"
    + cal.getTimeInMillis());
    long endTime=cal.getTimeInMillis();
    /*Date endNow = new Date();
    print "endNow"+endNow
    strDate = sdfDate.format(endNow);
    Date endTime=sdfDate.parse(strDate);
    print "endTime"+endTime*/
    return endTime;
}

def differenceTime(long startTime,long endTime){
    print "requestEndTime"+endTime
    print "requestStartTime"+startTime
    long timeDifference = endTime - startTime;
    return timeDifference;
}

Here I am trying to get the starttime and endtime and trying to calculate the difference. I do know whether the way I implemented is right? Please tell me usually how the time difference is being calculated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T18:03:40+00:00Added an answer on June 17, 2026 at 6:03 pm

    Instead of using Calendar it’s easier to use System.currentTimeMillis():

    def startTime() { 
        long startTime=System.currentTimeMillis();
        return  startTime;
    }
    

    Calculating time difference based on System.currentTimeMillis() is very common in Java, and you’ll doing it right (I mean endTime - startTime)

    So, your code could looks like:

    long startTime = System.currentTimeMillis();
    // .....
    // processing request
    // .....
    long endTime = System.currentTimeMillis();
    long differenceTime = endTime - startTime;
    log.debug("Request time: " + differenceTime);
    //or
    log.debug("Request time: " + TimeUnit.MILLISECONDS.toSeconds(differenceTime) + " sec");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a search button and when user clicks it I am displaying UISearchBar
I have an input text box and a search submit button, and when user
I want to close my UISearchDisplayController when the user clicks the Search button since
I have a partial view that when the user clicks a button, some data
I have a search button tied to an update panel as a trigger like
I have a search box and search button. I want to call a javascript
I have a simple ProgressDialog but I realized if I press the search button
I have 6 text boxes on an asp page and one search button. Users
I have a simple search form with a box and a button. <form action
I have a basic form with a search input and a submit button within.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.