Casper7526
Casper7526

Reputation: 341

Getting difference in time_t

I compute a start time like so ...

time_t test = (int)difftime(time(0), gStatStartTime);
struct tm tempinfo;             
localtime_s(&tempinfo, &test);              
char buffer2[80];
strftime(buffer2, 80, "[%H:%M:%S]", &tempinfo);

time(&gStatStartTime);

When I compute a "stop" time for a 1-second run, however, my program prints [19:00:01]. The seconds value is correct, but the 19 hours is terribly wrong. What could be the problem?

Upvotes: 1

Views: 216

Answers (1)

Michael Burr
Michael Burr

Reputation: 340208

Use gmtime_s() instead of localtime_s()

Upvotes: 2

Related Questions