cgpsunix-timestampgps-time

Converting unix time into readable time


I've got the unix time since January 1st 1970 (E.G 1531074816) from my GPS module, how do I convert this into a readable format? I only need to get the current hour, minutes and seconds. I'm not worried about the day or date. I'm also using C. Thanks.


Solution

  • use gmtime

    #include <stdio.h>
    #include <time.h>
    
    int main()
    {
        static const time_t unixtimestamp = 1230728833;
        struct tm *tmp = gmtime(&unixtimestamp);
    
    
        printf("%02d:%02d:%02d\n", tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
        return 0;
    }