• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

timing calculations

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am having problems calculating time for my mini Computer Based Training project.The system should calculate and monitortime spent by a trainee (2 hrs)on a pc and subtract it from the duration of the course (e.g 20hrs ) until the course is complete.The facilitator logs a trainee on the server and that should start the timer.
so i have my forms (GUI), a class called DataServices(containing methods and SQL statements to access database),and mySQL database.snipetts of my code;

LOGIC: endTime = startTime + 2hrs
span = endTime - startTime
if currentTime = endTime Or
currentTime - startTime = span then sessionEnded()


public class DataService {
private Date time = new Date();
private DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT);

how do you add or subtract time?how do you make your textfields accept/display time.how do you get current time at certain intervals?hrs/mins?

i came across something like:

startTime = System.currentTimeMillis();
endTime = System.currentTimeMillis();

how and where do i declare and use these; or maybe i need a stopwatch?please help , i am not a good programmer.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, welcome to the ranch!

I think you have the seeds for what you need there. The problem description sounds like you need to track the amount of time remaining out of the original 20 hours. You could start with the full 20 hours expressed as milliseconds:

long timeRemaining = 20 * MINUTES_PER_HOUR * SECONDS_PER_MINUTE * MILLIS_PER_SECOND;

and subtract each session. You were going the right direction for the length of each session - end time in millis minus start time in millis. Since we're in an OO language, let's encapsulate that timing in a StopWatch class as you suggested. Can you imagine very simple StopWatch code that would work like this?

Write some real code and post what you have. I bet you're going to bring this together pretty quickly.
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic