Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 04-25-2007, 04:30 PM   #1
Registered: Nov 2005
Posts: 38

Rep: Reputation: 15
Question Lap Timer Software or Script NEEDED!

Hello everyone,

I'm sorry if this sounds like a stupid question but I've tried searching and haven't been able to find a suitable answer.

Is there a timer software with an unlimited lap feature for linux or as a java applet?
Something like this lap timer.

If not, then what's the quickest way to make a simple script that will record the time whenever a key is pressed.

What I basically want to do is start a timer and then whenever I press the space bar, have:
1. the time elapsed since the last press
2. the time elapsed since the timer was started

recorded into a text file. I want to have this repeated an unlimited number of times.

So, the generated text file should look something like this:

#HH:MM:SS.sss = hours:minutes:seconds.seconds


The way I'm doing this currently is binding an alias to the date command and having the output appended to a text file and then processing and formatting that data. Something that automatically does all this in one step would be great.

Thanks for any help and any pointers!


Last edited by dezireduser; 04-25-2007 at 04:48 PM.
Old 04-25-2007, 08:18 PM   #2
Registered: May 2006
Location: New Zealand
Distribution: ubuntu, gentoo at uni
Posts: 30

Rep: Reputation: 15
would something written in java be suitable I think I could code something up fairly easily.
Old 04-26-2007, 06:03 AM   #3
Registered: May 2006
Location: New Zealand
Distribution: ubuntu, gentoo at uni
Posts: 30

Rep: Reputation: 15
This should do the trick, it'll tell you what to do when you run it. If you want to save the results just redirect it to a file.

import java.lang.Exception;
import java.text.SimpleDateFormat;
import java.util.Date;

public class LapTimer {

	public static void main(String[] arg){
		long glStart;
		long lapStart;
		char ch = ' ';
		SimpleDateFormat formatter = new SimpleDateFormat("KK:mm:ss:SSS");
		glStart = System.currentTimeMillis();
		lapStart = 0;

		System.out.println("# format is: Hours:Minutes:Seconds:Milliseconds");
		System.out.println("# Elapsed time, Lap Time");
		System.out.println("# press enter to end the current lap");
		System.out.println("# type 'q' and enter to quit");

			long elapsed,lapTime;

			if(ch != ' '){
				elapsed = System.currentTimeMillis() - glStart;

				if(lapStart == 0){ // if on first lap
					lapTime = elapsed;
				} else {
					lapTime = elapsed - lapStart;
				System.out.print(formatter.format(new Date(elapsed)) + "," + formatter.format(new Date(lapTime)));
				lapStart = elapsed;
			//ask for new control character

				ch = (char);
			}catch(Exception ex){
				System.out.println("Oh No!!!!");

		}while(ch != 'q');
Old 04-26-2007, 06:12 AM   #4
Registered: May 2006
Location: New Zealand
Distribution: ubuntu, gentoo at uni
Posts: 30

Rep: Reputation: 15
actually I just tried redirecting it and it doesn't work too well.


code, script, timer

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
timer in a shell script sanjith11 Programming 8 04-15-2011 11:32 PM
Multimedia timer (SMP friendly timer) bigqueso Linux - Kernel 0 03-15-2007 04:49 PM
Timer software for Cybercafe running on Red Hat jibade Linux - Software 1 10-04-2004 12:42 AM
speed up the slack in my lap Goatdemon Slackware 42 02-22-2004 03:34 AM
Bitchix timer script zeky Linux - Software 0 11-16-2002 11:24 AM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:39 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration