开发者

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

开发者 https://www.devze.com 2023-02-20 16:58 出处:网络
In C/C++, suppose I have the following values: int year = 2010; int month = 6; int day = 15; int hour = 14;

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's the easiest way to开发者_C百科 convert this to a timeval? I think timeval is time since Jan 1, 1970? But to calculate this manually everytime seems very tedious. What's the easiest (and fastest) way to do this?

Thanks


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


You might want to look into std::mktime().

0

精彩评论

暂无评论...
验证码 换一张
取 消