Tom
Tom

Reputation: 9643

c++ time manipulation using time_t in Win platform

Well i want to manipulate time with a time_t variable in this way:

  1. time1 = get the current time as time_t (say it's 9:30 now)
  2. use SYSTEMTIME to see if we passed 10:00
  3. if we didn't pass 10:00 : evaluate what (time_t)time2 would be in 10:00. and set time3 = time2 - time1 in order to get in seconds how much is left till 10:00.

I don't want to use boost because i don't want to link my application to it. I hope i made it clear that i want to check what's the time now and what it would be in say 10:00 to get the time difference between now and a pre defined time (not date).

Upvotes: 0

Views: 1088

Answers (2)

James Curran
James Curran

Reputation: 103515

time_t time1;
time(&time1);

tm time0  = *localtime( &time1);

if (time0.tm_hour == 22 && time0.tm_min == 0)
    ; // it 10PM
else
{
    // force time0 to 10PM
    time0.tm_hour = 22;
    time0.tm_min = 0;
    time_t time2 = mktime(&time0);   
}

Upvotes: 1

wallyk
wallyk

Reputation: 57774

Either use GetSystemTime() so everything is Windows, or call time() to get the current time using the C runtime values.

Upvotes: 0

Related Questions