yes a simple integer counter would seem better for your counter, any reason why you use a Calendar instance?
Main Topics
Browse All TopicsI currently display the current time. I would also like to start a plus count when a particular event occurs. The plus
count would start at zero when it is triggered. I would like to display the plus count in seconds.
Here is my code which doesn't work:
Start the Plus Count by setting a calendar Object to Zero.
{
private Calendar pluscount;
// I want to start the clock at zero and have it start counting up. I then will parse the fields to determine plus count.
pluscount = plusCount.getInstance();
pluscount.set(Calendar.HOU
pluscount.set(Calendar.MIN
pluscount.set(Calendar.SEC
pluscount.getTime();
irigTimeProd.fireEvent(plu
}
public void irigTimeUpdate(com.slrsc.o
{
myTimeStamp = event.getTimestamp();
myPlusCount = event.getPlusTime(); // get plus count
//Convert to seconds (plus Count is displayed in seconds)
if (myPlusCount.get(Calendar.
{
hourValue = 0;
hourValue = myPlusCount.get(Calendar.H
hourValue = hourValue * 3600;
}
if (myPlusCount.get(Calendar.
{
minuteValue = myPlusCount.get(Calendar.M
minuteValue = minuteValue * 60;
}
else if (myPlusCount.get(Calendar.
{
minuteValue = 0;
}
event.getPlusTime().getTim
minuteValueHolder = hourValue + minuteValue + myPlusCount.get(Calendar.S
myPlusCountString = ("+" + minuteValueHolder);
myTimeString = (myTimeStamp.get(Calendar.
irigDataMessage(myTimeStri
plusCountDataMessage(myPlu
}
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
any reason why you use a Calendar instance?
I have a command file that is timestamped according to plus time. My intention was to use a Calendar instance for plus
time so I could use the before and after methods of the Calendar to compare to the current calendar time.
For instance, lets say it is 1:00 p.m. My commands are scheduled to begin at +120 seconds after I receive an external
signal. One I receive the signal I start my plus count. I then will use the before and after methods of the Calendar to determine when I should send the commands. If the current time is 1:02:01 p.m. and my calendar instance is +121 seconds, I know I should send the command that was timestamped at +120 seconds.
I have tried to set the Calendar instance to zero (hours, minutes, seconds) but it will not start the clock, it stays at zero.
Will the system time work?
long startingTime = System.currentTimeMillis()
This is in milisecons so you'll have to divide by 1000 to get the number of seconds
This does not meet my requirements. I need a plus count that starts counting from zero seconds on up.
I'm still not sure I fully understand what you're doing... so I'll try to explain it as I see it :)
You're basically creating a timer, in which it starts at 0 and then counts up. Then at some defined time it does something. Is this correct?
int numOfSeconds
long starting System.currentTimeMillis()
sleep(1000); // sleep 1 second
numOfSeconds = (System.currentTimeMillis(
switch numOfSeconds {
case 120 : { do something }
}
Anyway.. if this won't work... we'll hammer our the calendar
As another thought have you thought of timer tasks?
Ok, Moroni24, You have led me on the right path.
I have been able to generate a plus count and save it in a Calendar instance.
The problem that I'am having now is when I compare the two Calendar instances
they are never equal.
Shouldn't a Calendar instance be modifiable with a new time?
Here is my code.
public void irigTimeUpdate(com.slrsc.o
{
currentTime = event.getTimestamp(); // get the current time
plusCountTime = myTime.getPlusCountTime(10
// the time the event occured, 2nd parameter is the
// time the event occured.
if (currentTime.equals(plusCo
{
"Send out camera command"
}
}
public Calendar getPlusCountTime(int plustime, Calendar LiftoffTime)
{
int seconds1 = LiftoffTime.get(Calendar.S
seconds1 = seconds1 + plustime;
LiftoffTime.set(Calendar.S
return LiftoffTime;
}
Ok, here it is
liftOffCount = myTime.getPlusCountTime(10
public Calendar getPlusCountTime(int plustime, long liftoffTime)
{
plusCount1 = pluscount1.getInstance();
plusCount1.setTimeInMillis
plusCount1.add(Calendar.SE
return plusCount1;
}
public void irigTimeUpdate(com.slrsc.o
{
myTimeStamp = event.getTimestamp();
myPlusCount = event.getPlusTime();
myPlusCountString = myTime.getPlusTimeSecondsS
myTimeString = myTime.getSystemTimeString
irigDataMessage(myTimeStri
plusCountDataMessage(myPlu
if (myTimeStamp.after(liftOff
{
liftOffDataMessage("SEND Command");
}
}
Business Accounts
Answer for Membership
by: Moroni24Posted on 2004-06-18 at 13:51:52ID: 11348417
If you're all trying to do is measure lasped time then the calendar may be overkill.
;
Will the system time work?
long startingTime = System.currentTimeMillis()
This is in milisecons so you'll have to divide by 1000 to get the number of seconds
HTH
Preston