Convert month / day / year / time to timeval in C / C ++

In C / C ++, suppose I have the following values:

int year = 2010; int month = 6; int day = 15; int hour = 14; int minute = 52; int seconds = 34; int microseconds = 141231; 

What is the easiest way to convert this to timeval? I think timeval is the time since January 1, 1970? But figuring it out manually each time seems very tedious. What is the easiest (and fastest) way to do this?

thanks

+4
source share
2 answers

You can use mktime(3) to convert the struct tm structure to time_t . After you have time_t , you can copy it and your microseconds directly to the struct timeval structure.

+8
source

You might want to learn std::mktime() .

+4
source

Source: https://habr.com/ru/post/1345951/


All Articles