![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Dec 2005
Posts: 2
Rep Power: 0
![]() |
How to handle time....
I have a strange question.
I have a parameter that is time, represented in seconds. I also have a structure that has seconds, minutes, hours, days,etc. How would I go about filling the members of the structure? in your language of choice. Its the algorithim im looking for. ~k |
|
|
|
|
|
#2 |
|
Professional Programmer
Join Date: May 2005
Location: Bad Nauheim, Germany
Posts: 436
Rep Power: 4
![]() |
Ask yourself how many seconds are in a minute, how many minutes in an hour, how many hours in a day, etc. This will get you going in the right direction.
__________________
-Steven "Is this a piece of your brain?" - Basil Fawlty |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Dec 2005
Posts: 2
Rep Power: 0
![]() |
I used this site as a template.
http://www.ibiblio.org/obp/thinkCS/c...ish/chap11.htm Time makeTime (double secs) {
Time time;
time.hour = int (secs / 3600.0);
secs -= time.hour * 3600.0;
time.minute = int (secs / 60.0);
secs -= time.minute * 60.0;
time.second = secs;
return time;
}Here they are using 'sec's as a running counter. |
|
|
|
|
|
#4 |
|
Hobbyist Programmer
Join Date: Jun 2005
Location: New Mexico
Posts: 228
Rep Power: 4
![]() |
Don't know what your app is gong to do. However, time and date is a lot messier than you would ever believe. DO NOT use the above if you require strict accuracy - leap seconds will get you in trouble, for example....
What you show above will work fine on a seconds elapsed since midnight kind of timer, where you don't care if there are variations on the number of seconds in the day. |
|
|
|
|
|
#5 |
|
Hobbyist Programmer
Join Date: Jun 2005
Location: New Mexico
Posts: 228
Rep Power: 4
![]() |
Here is some quick information on Calendrics:
http://aa.usno.navy.mil/data/docs/JulianDate.html If you're on Unix, and your locale is default or "C" try cal 1752 |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|