Hello, I got some code from:

http://stackoverflow.com/questions/1859201/add-seconds-to-a-date

this is the code:

#include <time.h>
#include <stdio.h>

int main()
{
    time_t now = time( NULL);

    struct tm now_tm = *localtime( &now);


    struct tm then_tm = now_tm;
    then_tm.tm_sec += 50;   // add 50 seconds to the time

    mktime( &then_tm);      // normalize it

    printf( "%s\n", asctime( &now_tm));
    printf( "%s\n", asctime( &then_tm));

    return 0;
}

Unfortuantely I do not know much about the code, and need to write a program that records a time, and compares two times. I do not know much about the datatypes time_t, struct tm, and the functions localtime, mktime, asctime, etc. Any information on this would be helpful. I am hoping to write some firmware which will activate after a certain amount of time, once I know how to use c time I will be able to finish the firmware.

Recommended Answers

All 3 Replies

Compare tm_sec relative to each other

Yes, but is there any kind of online refrence I can use to read about the functions?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.