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

  • Home
  • SEARCH
  • 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

Ask A Question

Stats

  • Questions 243k
  • Answers 243k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can't. XHR is subject to the same origin policy.… May 13, 2026 at 7:50 am
  • Editorial Team
    Editorial Team added an answer It looks like your doing 3 saveFAQ calls that EasyMock… May 13, 2026 at 7:50 am
  • Editorial Team
    Editorial Team added an answer According to the Reflector, BackgroundWorker.RunWorkAsync which is called from the… May 13, 2026 at 7:50 am

Related Questions

I am currently using generators as a quick way to get the progress of
It's not the first time I come across delegates and I am as confused
I am trying to use OBJECT to embed content from a remote server into
I have an Oracle database where I'm trying to select a user field from

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.