Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[tlug] [OT] Displaying time and starting from zero



TLUG,

I suppose this is kind of a general programming question in a way,
although in this instance I'm specifically working with JavaScript.

I have a timer thing that sets a countdown for an hour. It all works
fine, but when the display shows the timer, it shows it as starting from
0:59.

I think this is because I set the countdown timer in milliseconds at
3600000 milliseconds, but the timer starts at zero, not one. This means
the actual time being set is 59 minutes and 59.999 seconds.

Maybe. I think. Not sure, really. Is time usually counted from zero?

I thought the quick and easy solution to get the display to show 1:00
instead of 0:59 would be to add one millisecond to my timer: 3600001.
That didn't do it. So I added a whole second: 3601000. That worked, but
then it felt like I was just adding arbitrary amounts of time.

Which got me wondering if there was a better way to do this. Like
setting some kind of math rounding function or string offset so you can
get an hour countdown that displays as being from 1 hour and not 59
minutes and 59 seconds.

By the way, I'm bad at math, so I might have messed up a number. I
usually have to dial things in when I deal with numbers because I mess
things up a lot. So if I've thrown the example numbers a bit, I hope my
explanation still makes sense.

-- 
Dave M G


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links