Thread: Help With Time Plzzz!!

  1. #1
    Me pwn you.
    Join Date
    Feb 2006
    Location
    At my computer or in my bed.
    Posts
    46

    Help With Time Plzzz!!

    First of all I am relatively new to programming, and I need to know how to access the system's time, in hour, minute, second, and so on. Please help me with this... I think I need to #include
    <time.h>, or is it <sys\time.h>, or am I way off base?

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    <ctime> (or time.h if you will) would be where to go, yes.

    Then check this site out. It has a list of the functions and how to use them:

    http://www.cplusplus.com/ref/ctime/
    Sent from my iPadŽ

  3. #3
    Me pwn you.
    Join Date
    Feb 2006
    Location
    At my computer or in my bed.
    Posts
    46
    Thankyou, however I'm not sure that's what I'm looking for. I went to the site, but
    That would require complex math to convert the number of seconds since midnight,
    Jan 1, 1970 into current hour, minute, and second. I would appreciate any further help
    on the subject.
    Last edited by Dagger; 02-01-2006 at 04:32 PM.

  4. #4
    Slave MadCow257's Avatar
    Join Date
    Jan 2005
    Posts
    735
    An example
    Code:
    #include <ctime>
    #include <iostream>
    using namespace std;
    int main()
    {
    	time_t example;
    	struct tm  * part2;
    	time(&example);
    	part2 = localtime( &example );
    	cout << part2->tm_hour << "\n"; //example of displaying single part of the time
    	cout << asctime(part2); //displaying all of the time
    }

  5. #5
    Me pwn you.
    Join Date
    Feb 2006
    Location
    At my computer or in my bed.
    Posts
    46

    Lightbulb

    Thanks, I think this is all I needed...

  6. #6
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    You gotta look at all the functions in <ctime> before you decide they don't work. That site has good examples, as well.
    Sent from my iPadŽ

  7. #7
    Me pwn you.
    Join Date
    Feb 2006
    Location
    At my computer or in my bed.
    Posts
    46
    I did look at everything that seemed useful. I wanted to access hour, minute, and second
    individually, not all at once or in a string or have to convert ten billion seconds into
    minutes or hours, or any other nonsense. Which example did you think would work for
    what I sought? Tell me and I'll check it out. Thanks...

  8. #8
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 10:43 AM
  2. Replies: 11
    Last Post: 03-29-2009, 12:27 PM
  3. calculating user time and time elapsed
    By Neildadon in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2003, 06:00 PM
  4. Is this really true or it's just science fiction?
    By Nutshell in forum A Brief History of Cprogramming.com
    Replies: 145
    Last Post: 04-09-2002, 06:17 PM
  5. time class
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-11-2001, 10:12 PM