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 133807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:29:57+00:00 2026-05-11T06:29:57+00:00

How to get the time from a Chronometer? I tried getText, getFormat, getBase, etc,

  • 0

How to get the time from a Chronometer? I tried getText, getFormat, getBase, etc, but none of them could work.

Example code snippet:

Chronometer t = (Chronometer)findViewById(R.id.toptime); long time = SystemClock.elapsedRealtime()-t.getBase(); Log.d(null,'Was: '+time); //time is not the proper time for some reason - it is a random number between 0 and 50 t.setBase(SystemClock.elapsedRealtime()); t.start(); 
  • 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. 2026-05-11T06:29:58+00:00Added an answer on May 11, 2026 at 6:29 am

    If you look at the source of the Chronometer class, you’ll see that it doesn’t store the elapsed time in a field and it calculates it internally every time it needs to update the display.

    However it’s relatively easy to do the same in your own code:

    long elapsedMillis = SystemClock.elapsedRealtime() - chronometerInstance.getBase(); 

    This assumes that you have started your clock something like this:

    chronometerInstance.setBase(SystemClock.elapsedRealtime()); chronometerInstance.start(); 

    Here’s a full example:

    public class ChronoExample extends Activity { Chronometer mChronometer;  @Override protected void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);      LinearLayout layout = new LinearLayout(this);     layout.setOrientation(LinearLayout.VERTICAL);      mChronometer = new Chronometer(this);     layout.addView(mChronometer);      Button startButton = new Button(this);     startButton.setText('Start');     startButton.setOnClickListener(mStartListener);     layout.addView(startButton);      Button stopButton = new Button(this);     stopButton.setText('Stop');     stopButton.setOnClickListener(mStopListener);     layout.addView(stopButton);      Button resetButton = new Button(this);     resetButton.setText('Reset');     resetButton.setOnClickListener(mResetListener);     layout.addView(resetButton);              setContentView(layout); }  private void showElapsedTime() {     long elapsedMillis = SystemClock.elapsedRealtime() - mChronometer.getBase();                 Toast.makeText(ChronoExample.this, 'Elapsed milliseconds: ' + elapsedMillis,              Toast.LENGTH_SHORT).show(); }  View.OnClickListener mStartListener = new OnClickListener() {     public void onClick(View v) {         mChronometer.start();         showElapsedTime();     } };  View.OnClickListener mStopListener = new OnClickListener() {     public void onClick(View v) {         mChronometer.stop();         showElapsedTime();     } };  View.OnClickListener mResetListener = new OnClickListener() {     public void onClick(View v) {         mChronometer.setBase(SystemClock.elapsedRealtime());         showElapsedTime();     } }; } 

    One somewhat confusing thing about Chronometer is that you can’t really use it as a stopwatch that gets started, stopped and restarted again. When it’s running, it will always show the time elapsed since you last reset it, no matter how many times and for how long you have stopped it in the meantime. When it is stopped, it simply stops updating the display.

    If you need something like a stopwatch you’ll have to subclass Chronometer or maybe create your own version using the source.

    alt text

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

From time to time I get a System.Threading.ThreadStateException when attempting to restart a thread.
When I use DateTime.Now I get the date and time from the server point
What interrupt would you hook from DOS to get the real-time clock?
How can my app get a valid last time connected to domain timestamp from
How to get time part from SQL Server 2005 datetime in HH:mm tt format
This warning message I get from time to time from SQL server ... Warning:
My Android app requires to get the current date and time from Internet .
I need to get the current time from one of internet time server in
i get a epoch time returned from a webservice wich is about 3 years
How to get directories,subdirectories, files creation date & time from FTP remote Server in

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.