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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:02:39+00:00 2026-06-15T23:02:39+00:00

I am trying to make a stopwatch in android that includes hours and milliseconds.

  • 0

I am trying to make a stopwatch in android that includes hours and milliseconds. My chronometer always starts at 7:00:00.000 or in 24 hour format 19:00:00.000. Here is the code:

public class MainActivity extends Activity {
   TextView tv;
   long init,now,time;

   @Override
   public void onCreate(Bundle savedInstanceState) {
       //...
       myChronometer.setOnChronometerTickListener(new OnChronometerTickListener() {
            public void onChronometerTick(Chronometer cArg) {
                SimpleDateFormat timeFormat = new SimpleDateFormat("hh:mm:ss.S");
                now=System.currentTimeMillis();
                time=now-init;
                String s2 = timeFormat.format(time);
                tv.setText(s2);
            }
        });
       final ImageButton buttonStart = (ImageButton)findViewById(R.id.start);
       buttonStart.setOnClickListener(new Button.OnClickListener(){
       @Override
       public void onClick(View v) {
           init=System.currentTimeMillis();
           myChronometer.setBase(init);
           myChronometer.start();
       }});

   }

}

Is there anyway to start the chronometer at zero and continue the time from there?
Thank you

  • 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-15T23:02:40+00:00Added an answer on June 15, 2026 at 11:02 pm

    The 7 hour difference is likely due to your timezone. SimpleDateFormat uses your system’s timezone by default, whereas System.currentTimeMillis() gives you the time in UTC.

    This should fix your problem, in onChronometerTick():

    SimpleDateFormat timeFormat = new SimpleDateFormat("H:mm:ss.S");
    timeFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
    now=System.currentTimeMillis();
    

    Notice I changed hh to H in your format string.

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

Sidebar

Related Questions

I'm trying to make a stopwatch for android as part of a score board
I am trying to make a class that when it starts it starts a
I'm trying make an entity with doctrine that has three associations with other entities
Trying to make this jQuery filter that uses .find case-insensitive. For example, when the
Right, I'm trying to make an app that has a calculation that involves a
Trying to make td elements clickable. Here's my HTML: <td id=A3 class= open-square><a href=/gameplay/A3></a></td>
I are trying to make to a stopwatch app and facing problems getting it
Hi I am trying to make a global class that I can use in
Trying to make a simple client that consumes a web service using RemObjects SDK,
I'm new to WPF and I'm trying to make a simple app, a stopwatch.

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.