convert current time into seconds?

calculating number of seconds from the current time?

Page 1 of 1

6 Replies - 16096 Views - Last Post: 07 May 2008 - 03:31 PM Rate Topic: -----

#1 chronoTrigger  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 60
  • Joined: 08-October 07

convert current time into seconds?

Posted 01 May 2008 - 10:45 AM

does anyone know how can I get the total seconds based on the current time?

hour:minute into seconds
Is This A Good Question/Topic? 0
  • +

Replies To: convert current time into seconds?

#2 Martyr2  Icon User is online

  • Programming Theoretician
  • member icon

Reputation: 4187
  • View blog
  • Posts: 11,847
  • Joined: 18-April 07

Re: convert current time into seconds?

Posted 01 May 2008 - 10:51 AM

(hour * 3600) + (minutes * 60) = total number of seconds

:)
Was This Post Helpful? 0
  • +
  • -

#3 lockdown  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 6
  • View blog
  • Posts: 394
  • Joined: 29-September 07

Re: convert current time into seconds?

Posted 01 May 2008 - 10:54 AM

Ah beat me to it. Yeah thats what I would recommend.

This post has been edited by lockdown: 01 May 2008 - 10:54 AM

Was This Post Helpful? 0
  • +
  • -

#4 chronoTrigger  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 60
  • Joined: 08-October 07

Re: convert current time into seconds?

Posted 01 May 2008 - 10:55 AM

View PostMartyr2, on 1 May, 2008 - 10:51 AM, said:

(hour * 3600) + (minutes * 60) = total number of seconds

:)


:) thanks for the calculation method, but I meant, the C++ function itself that can access to current time and hopefully can access to both hour and minute so I can calculate into seconds like you have shown above. Sorry my question is kind of vague.

This post has been edited by chronoTrigger: 01 May 2008 - 10:56 AM

Was This Post Helpful? 0
  • +
  • -

#5 Martyr2  Icon User is online

  • Programming Theoretician
  • member icon

Reputation: 4187
  • View blog
  • Posts: 11,847
  • Joined: 18-April 07

Re: convert current time into seconds?

Posted 01 May 2008 - 11:26 AM

I knew it couldn't be that simple. Next time work on the vagueness a little. Precise questions deserve precise answers I always say. ;)


#include <stdio.h>
#include <time.h>
#include <iostream>
using namespace std;

int main ()
{
  // Create a raw time_t variable and a tm structure
  time_t rawtime;
  struct tm * timeinfo;

  // Get the current time and place it in time_t
  time ( &rawtime );

  // Get the locatime from the time_t and put it into our structure timeinfo
  timeinfo = localtime ( &rawtime );

  // Now we have access to hours, minutes, seconds etc as member variables of all type int
  int hour = timeinfo->tm_hour;
  int min = timeinfo->tm_min;

  // Just print out the hours and minutes to show you
  cout << "Hour is: " << hour << " and minutes are: " << min << endl;
  
  return 0;
}



Just an example for you to play with. Enjoy!

"At DIC we be time mastering code ninjas... with that said, I say it is miller time!" :snap:
Was This Post Helpful? 0
  • +
  • -

#6 chronoTrigger  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 60
  • Joined: 08-October 07

Re: convert current time into seconds?

Posted 01 May 2008 - 11:30 AM

View PostMartyr2, on 1 May, 2008 - 11:26 AM, said:

I knew it couldn't be that simple. Next time work on the vagueness a little. Precise questions deserve precise answers I always say. ;)


#include <stdio.h>
#include <time.h>
#include <iostream>
using namespace std;

int main ()
{
  // Create a raw time_t variable and a tm structure
  time_t rawtime;
  struct tm * timeinfo;

  // Get the current time and place it in time_t
  time ( &rawtime );

  // Get the locatime from the time_t and put it into our structure timeinfo
  timeinfo = localtime ( &rawtime );

  // Now we have access to hours, minutes, seconds etc as member variables of all type int
  int hour = timeinfo->tm_hour;
  int min = timeinfo->tm_min;

  // Just print out the hours and minutes to show you
  cout << "Hour is: " << hour << " and minutes are: " << min << endl;
  
  return 0;
}



Just an example for you to play with. Enjoy!

"At DIC we be time mastering code ninjas... with that said, I say it is miller time!" :snap:


Thanks I will definitely play around with your given example.
Was This Post Helpful? 0
  • +
  • -

#7 chronoTrigger  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 60
  • Joined: 08-October 07

Re: convert current time into seconds?

Posted 07 May 2008 - 03:31 PM

I don't know why, but I included the header file like your sample code shown above, my program has error, so I'm using SYSTEMTIME instead, and I believe I can access to hour, minute, second. So far it works.

Thanks Martyr2.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1