Search code examples
c++datetimelocaltimetime-t

Converting localtime to time_t (C++)


I creating date() function on C++ http://aliarth.lt/date.cpp and I got one problem with localtome_to_time() conversion. Does anyone know how that local_time variable:

int time_integer = 12345;
time_t time = (time_t)time_integer;

tm *local_time = localtime(&time);
local_time->tm_year = 100;
local_time->tm_mon = 10;
local_time->tm_mday = 1;

Convert to time_t?


Solution

  • Try mktime, here is its signature:

    time_t mktime (struct tm * timeptr);
    

    Returns the value of type time_t that represents the local time described by the tm structure pointed by timeptr (which may be modified).