Retrieveing time.

Started by
4 comments, last by Xeneth 20 years, 2 months ago
Is there a way to get just the time. no date?

#include <time.h>
#include <iostream.h>
int main()
{
  time_t hold_time;
  hold_time=time(NULL);
  cout<<"The date is: "<<ctime(&hold_time);
}
[\source]

This is the only thing I could find but not sure how to get JUST the time of day out of it.
Technology can either save us or destroy us. Me ... I say it will destroy us if Microsoft is the example.
Will you play with me? (Grins Evilly)
Advertisement
gettimeofday()

EDIT: actually, localtime(), if you don't want to do as much work yourself.

"Sneftel is correct, if rather vulgar." --Flarelocke

[edited by - sneftel on February 22, 2004 1:36:19 AM]
Thanx, but that gives the same information as what I put. I'm looking to see how to pull the hour only from the before it get's convertid into 12 hour but I'm kind of new and they don't put many coments in the header files I got. All the help I found on the web only shows the 'as-is', not how to look at a spicifics sperate. (month, day, hour, min, sec, ect. all in seperate outputs.)

Technology can either save us or destroy us. Me ... I say it will destroy us if Microsoft is the example.

[edited by - Xeneth on February 22, 2004 9:26:54 AM]
Will you play with me? (Grins Evilly)
This is starting to get annoying. I can't understand this. How can I get the hour of day while still in 24H format? If I can't figure this out, I'm going to have to cut that part of the game out for later, but that will Sieriously cut into the fun. If you know how to do this, Please post a sample code I can look at.

Technology can either save us or destroy us. Me ... I say it will destroy us if Microsoft is the example.

[edited by - Xeneth on February 22, 2004 10:54:13 AM]
Will you play with me? (Grins Evilly)
quote:Original post by Xeneth
Thanx, but that gives the same information as what I put. I''m looking to see how to pull the hour only from the before it get''s convertid into 12 hour but I''m kind of new and they don''t put many coments in the header files I got. All the help I found on the web only shows the ''as-is'', not how to look at a spicifics sperate. (month, day, hour, min, sec, ect. all in seperate outputs.)

look at localtime().

"Sneftel is correct, if rather vulgar." --Flarelocke
I''m an idiot. Thanx nobody.

The reason I could never pull tm_hour from the new structure was I was tring o put in the var. like ''struct.variable'' (the code that''s in my testing). I forgot about -> when dealing with a pointer.


Technology can either save us or destroy us. Me ... I say it will destroy us if Microsoft is the example.
Will you play with me? (Grins Evilly)

This topic is closed to new replies.

Advertisement