'how to use clock_gettime

I am trying to use the clock_gettime function, but can't figure it out what are the needed headers (or what am I doing wrong if it's not a question of headers). This is my code:

#include <stdio.h>
#include <unistd.h> /*for CLOCK_REALTIME? */
#include <time.h>

#define NANO_TO_MILLI(N) ((N)/ 1000000)


struct TimeStruct
{
    time_t sec;        
    time_t nano;  
};

typedef struct TimeStruct TimeStruct;

void getTime (char* _timeStr);

int main()
{
    char* time;
    getTime(time);
    printf("%s\n", time);
    
    return 0;
}


void getTime (char* _timeStr)
{
    time_t milli;
    TimeStruct *curTime;
    struct tm* info;
    
    clock_gettime(CLOCK_REALTIME, curTime);
    milli = NANO_TO_MILLI(curTime-> m_nano);
    
    info = localtime(&(curTime-> m_sec));
    sprintf(_timeStr, "%d-%d-%d %d:%d:%d.%d", 1900 + info->tm_year, info->tm_mon, info->tm_mday, info->tm_hour, info->tm_min, info->tm_sec,  (int)milli);
    
}

I am getting the following errors:

implicit declaration of function clock_gettime

CLOCK_REALTIME undeclared

What am I missing?

I am compiling with gcc (linux) with ansi and pedantic flags



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source