   time(0) problems
  I'm working with time, and I can't get a current time on a second try. I'm working with std::tm, std::time_t, and my books don't make any sense.  My start up time code is as follows:std::time_t startTime = *time(0);std::tm curTime = * std::localtime(&startTime);int tempCurTime[3];tempCurTime[0] = curTime.tm_hour;tempCurTime[1] = curTime.tm_min;tempCurTime[2] = curTime.tm_sec;The above works fine, but I can't figure out how to get the current time from the system after the above code.  Below is what I try and it fails to compile:startTime = *time(0);curTime = * std::localtime(&startTime);Although the compiler says: time cannot be used as a function I can't find any other code to get the current time.Thank you in advance,BladeStone   
  Unless you are using this to display the system time, why not use the return value of std::time() as an integer?   ;  Oh gaud, Here was the problem.  The code doesn't like to be in a class-function. So I made a free floating command called GetTimeNow();, see below is exactly how I was able to get around the compiler issue;std::time_t GetTimeNow(void) return time(0);... // some where deep into class methods/functionsstd::time_t bob = GetTimeNow();... and poof no more compiler issues, on top of that, it does work :)   ;  std::time ... I haven't heard of it, that's why, but I'll look it up.Thank you   ;Quote:Original post by BladeStoneOh gaud, Here was the problem.  The code doesn't like to be in a class-function.Do you mean "There is some kind of problem that I don't understand, if I put the code into a member function of some class"?If so - have you considered that if that class defines a member called 'time', it will be selected in preference to the global function std::time (because the member is in a tighter scope)?That said, your free function is probably a good thing to keep around. :)   ;  Yes I did find I was calling two differant things timetime(0);time[3];  which to me are two differant things, but I changed time[3] to msgTime[3]; just to be more clear to myself and to any one who might also use it.Yes, for some reason, if you put std::time_t bob = time(0); it a class member function the system would not compile, but move time(0) into it's own stand alone function and things work fine.New Problem relating to time:It looks like time(0); stores the first call to time, and then never updates.  How do I get the current time? I've been looking through my code and manuals, and still no skill/luck.   ;  time(0) will always return the current time, in seconds, since the epoch (probably Jan. 1, 1970. I'm not sure if the standard dictates this, but I think it does). If you call the function more than once in the same second it will return the same value for that second over and over again. the standard function clock returns the number of ticks (where the number of ticks per second is implementation defined as CLOCKS_PER_SEC), but probably isn't better than 1 ms resolution and more likely far worse on most computers.So, depending on what you meant, the problem you might be experiencing is that resolution of std::time is too low for your needs.   ;  My thought is that if it's say 03 seconds and 900 milliseconds, then if I call it four times before the new second, I'll be getting 03 seconds of the current minute, but when I call it say at 04:0050 sec:milliseconds that I would be getting 04 as seconds.  Now if 03:0900 resets to 03:0000 after I call it, then that would be a problem.  I'm thinking that current time is exactly that, it checks the system clock.....Which might mean that current time(0) isn't making it into my varibles ... I'll go check.;  I cant remember if it rounds to the nearest second or just rounds down. However either way it just reads the time, doesn't change it. What exactly do you want it for though? Usually its much useful to a program in its integer form and you also depending on what your doing may want a time method with a higher precision.I certainly don't see the value of sticking parts of the tm struct into an array.   ;  It's for a 15 second fade timer on screen displayed messages.12:00:00 new message is added for display12:00:15 new message is going to fade out and be removed from the screenso I get current time, add 15 seconds to it, and set it to be compaired with current time, it it's equal or less then current time, then we turn on the fade, and poof, it fades and removed.   