1

Possible Duplicate:
Easy way to convert a struct tm (expressed in UTC) to time_t type

I am trying to convert a file path to UNIX time. The file path is of the format: "~/foo/bar/YYYYMMDD/HHMMSS.egg"

The time information contained within the path is already in UTC time. However, I can't find a way to convert UTC time to UNIX time, only to convert local time to UNIX time.

My relevant code is as follows:

struct tm * timeinfo;
time_t timeint;

time(&timeint);
timeinfo = gmtime(&timeint);

timeinfo->tm_year = year-1900;
timeinfo->tm_mon = month - 1;
...

timeint = mktime(timeinfo);

When I tried to validate this by checking the result at http://www.csgnetwork.com/unixds2timecalc.html, I found it was off by 4 hours, suggesting that it's actually inputting the time as if it were the time in EDT, not in UTC as it actually is. What do I have to do?

Community
  • 1
  • 1
Frank Harris
  • 305
  • 1
  • 6
  • 16
  • 2
    This might be a duplicate to this question: http://stackoverflow.com/q/283166/694576 – alk Jun 20 '12 at 15:47
  • It is, thanks. I didn't find it when I searched. Is the proper protocol to delete this question? – Frank Harris Jun 20 '12 at 16:08
  • As far as I observed such dupe issues, your question would be closed, rather then deleted. Anyway me, I do not seem to have the rights to vote for closure. – alk Jun 20 '12 at 16:25
  • I do not have the rights to vote for closure either, but I flagged as a duplicate question. – Cacho Santa Jun 20 '12 at 16:41
  • @cacho Aaah, that's way it works, by flagging. Thanks for the hint. – alk Jun 20 '12 at 18:21

0 Answers0