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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:56:39+00:00 2026-06-13T22:56:39+00:00

My stopwatch is giving me a weird time. It shows as 16:00:00:000, it also

  • 0

My stopwatch is giving me a weird time.
It shows as 16:00:00:000, it also is putting the seconds into the millisecond slot. I think the problem is the date formatter somehow. Without the dateformater adn just using a decimalformater it comes out correctly. I just need it to show hours, minutes and seconds.

public class StopWatchTest extends JLabel implements ActionListener {

    private static final String Start = "Start";
    private static final String Stop = "Stop";
    private SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss.SSS");

    private Timer timer = new javax.swing.Timer(100, this);
    private long now = System.currentTimeMillis();

    public StopWatchTest() {
        this.setHorizontalAlignment(JLabel.CENTER);
        this.setText(when());
    }

    public void actionPerformed(ActionEvent ae) {
        setText(when());
    }

    public void start() {
        timer.start();
    }

    public void stop() {
        timer.stop();
    }

    private String when() {
        return df.format((System.currentTimeMillis() - now) / 1000d);
    }

    private static void create() {
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        final StopWatchTest jtl = new StopWatchTest();
        jtl.setFont(new Font("Dialog", Font.BOLD, 32));
        f.add(jtl, BorderLayout.CENTER);

        final JButton button = new JButton(Stop);
        button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                String cmd = e.getActionCommand();
                if (Stop.equals(cmd)) {
                    jtl.stop();
                    button.setText(Start);
                } else {
                    jtl.start();
                    button.setText(Stop);
                }

            }
        });
        f.add(button, BorderLayout.SOUTH);
        f.pack();
        f.setVisible(true);
        jtl.start();
    }

    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                create();
            }
        });
    }
}
  • 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-13T22:56:40+00:00Added an answer on June 13, 2026 at 10:56 pm

    DateFormat formats an instant in time specified by the millisecond value and you are attempting to use it to format an interval. Nothing in the JDK covers your use case, but JodaTime does. You should use JodaTime, anyway.

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

Sidebar

Related Questions

I have absolute values of time (as in stopwatch not date/time) in various cells
So I'm trying to write a stopwatch app that displays time in milliseconds, but
I have a problem with time measuring that's really bothering me. I am executing
My stopwatch script runs flawlessly in the background on Android (counting up the time),
I'm working on this stopwatch application, and i keep getting this weird force close
I want to have a stopwatch on the site, which displays running time on
I am using the jQuery Stopwatch plugin to track time on a browser based
Does System.Diagnostics.Stopwatch count time during computer stand by?
Timers.Timer to create StopWatch. I use Timer.Elapsed to handle event that display time after
I use some kind of stopwatch in my project and I have start time

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.