Setting and Updating Absolute Time in Zephyr Application Using time_t Epoch

I am trying to configure the absolute time in my application, which at some point receives the time_t epoch value from an external source and should update it internally so that at any time I can retrieve the actual epoch to use in my application. I have tried to update the epoch using the function

void Set_Time( time_t epochTime )
{
    int ret;
    struct timespec ts;

    ts.tv_sec = epochTime;
    ts.tv_nsec = 0;
    ret = clock_settime( CLOCK_REALTIME, &ts );

    if ( ret < 0 )
    {
        LOG_WRN( "clock_settime returned error" );
    }
}

and then read it through the function time(NULL), but the latter always returns the value -1. Does anyone have any suggestions for implementing what I want?

Related