Question

I have parsed a date in C with strptime.

Now I have something like this:

debugLog(DEB_INFO, "observationDateConverted: %d-%d-%d %d:%d:%d\n", 
                        result.tm_year+1900, 
                        result.tm_mon + 1, 
                        result.tm_mday, 
                        result.tm_hour, 
                        result.tm_min, 
                        result.tm_sec);

With the latest date received in result (struct tm)

I have a bunch of milliseconds like this: 1396682344000 Which I want to add to that date to know the ending date.

How should I proceed?

Was it helpful?

Solution

General approach: Turn the struct tm into a timestamp (64bit int) and then add millis/1000.

time_t totalseconds = mktime(&result) + (millis / 1000);

You can then use the functions from C's time API to convert the time stamp back to struct tm .

OTHER TIPS

time_t totalseconds = mktime(&result);
uint_64 endtime = (totalseconds * 1000) + msDiff;

Or if you want the structure back:

time_t totalseconds = mktime(&result),
    endtimesec = totalseconds + msDiff;
struct tm * endTime = gmtime(&endtimesec);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top