Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 6th, 2005, 7:38 AM   #1
kompressor
Newbie
 
Join Date: Dec 2005
Posts: 2
Rep Power: 0 kompressor is on a distinguished road
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
kompressor is offline   Reply With Quote
Old Dec 6th, 2005, 8:09 AM   #2
stevengs
Professional Programmer
 
stevengs's Avatar
 
Join Date: May 2005
Location: Bad Nauheim, Germany
Posts: 436
Rep Power: 4 stevengs is on a distinguished road
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
stevengs is offline   Reply With Quote
Old Dec 6th, 2005, 8:49 AM   #3
kompressor
Newbie
 
Join Date: Dec 2005
Posts: 2
Rep Power: 0 kompressor is on a distinguished road
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.
kompressor is offline   Reply With Quote
Old Dec 6th, 2005, 9:35 AM   #4
jim mcnamara
Hobbyist Programmer
 
Join Date: Jun 2005
Location: New Mexico
Posts: 228
Rep Power: 4 jim mcnamara is on a distinguished road
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.
jim mcnamara is offline   Reply With Quote
Old Dec 6th, 2005, 9:42 AM   #5
jim mcnamara
Hobbyist Programmer
 
Join Date: Jun 2005
Location: New Mexico
Posts: 228
Rep Power: 4 jim mcnamara is on a distinguished road
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
and look at September for a quick surprise
jim mcnamara is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:16 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC