how do i get the time in seconds starting from 2000 to now

May 29, 2012 at 7:21pm
i need to get the time in seconds from jan 1 2000 up to today ,i cant seem to get it
thanks


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream> 
/* time example */
#include <stdio.h>
#include <time.h>

int main ()
{
  time_t seconds;

  seconds = time (NULL);
  printf ("%ld hours since January 1, 1970 \n", seconds);
  printf ("%ld hours since January 1, 1970 \n", seconds/3600);
  printf ("%ld \n", seconds/3600-262800);




    // give the user a chance to look things over before quitting
  
  system("pause");

  return 0;
} 
May 29, 2012 at 7:28pm
So what's the problem? If you want seconds, then why are you messing around with hours?
There's more than 262800 hours between 1.1.1970 and 1.1.2000, by the way.
May 29, 2012 at 7:32pm
i must have it wrong ill recheck it
thanks
May 29, 2012 at 7:59pm
allright im coming up with 392240776 from 1,1,january 2000 to now
May 29, 2012 at 8:08pm
i got it i hope .
thanks all

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream> 
/* time example */
#include <stdio.h>
#include <time.h>
using namespace std;


int main ()
{
  time_t seconds;

  seconds = time (NULL);
  printf ("%ld seconds since January 1, 2000 \n", seconds-946080000);
  

   cout << hex << seconds-946080000 << endl;


    // give the user a chance to look things over before quitting
  
  system("pause");

  return 0;
}
May 29, 2012 at 8:24pm
That's incorrect. See:
There are more than 262800 hours between 1.1.1970 and 1.1.2000, by the way.
May 29, 2012 at 8:30pm
i dont understand ,i figured the seconds per year times thirty years subtract that from total ,,right
May 29, 2012 at 8:35pm
You've heard of leap years, right?
May 29, 2012 at 8:35pm
How did you determine seconds per year? If you're older than 4, you should know it's not 365*24*60*60.
May 29, 2012 at 8:38pm
i did 24*60*60*365 and leap year ooh add a day every four?
May 29, 2012 at 8:40pm
Yes. You can just write that in code, makes it much more obvious what you're trying to do:
1
2
const int secondsBetween1970and2000=(365*30+7)*24*60*60;
... seconds-secondsBetween1970and2000);
Last edited on May 29, 2012 at 8:42pm
May 29, 2012 at 8:43pm
The mean should be 365,24-somethingish days per year. Either use that, or count leap years.
Last edited on May 29, 2012 at 8:43pm
May 29, 2012 at 9:01pm
ok i added 7.5 days both ways come out the same
thank yall
May 29, 2012 at 9:03pm
There are 7 leap years between 1970 and 2000, not 7.5.
Topic archived. No new replies allowed.