C++11
Have a cross platform code with usage of std::mktime on Ununtu 18 (x64) and QNX (x64)
On Ubuntu everything is ok. But on QNX mktime returns -1. errno = 3 What's wrong?
#include <iostream>
#include "ctime"
int main(int argc, char *argv[]){
const std::string token = "100901";
std::string dd = token.substr( 0, 2 );
std::string mm = token.substr( 2, 2 );
std::string yy = token.substr( 4, 2 );
struct std::tm date_tm = {};
date_tm.tm_mday = std::stoi( dd);
date_tm.tm_mon = std::stoi( mm) - 1;
date_tm.tm_year = std::stoi( yy) + 100;
if (std::mktime( &date_tm ) == -1);
{
std::cout << "Error";
}
return 0;
}
P.S. Tried init struct tm as:
struct std::tm date_tm = {0};
std::memset( &date_tm, 0, sizeof( date_tm ) )
Some notes:
1) if I call mktime twice - everything will be ok (will receive time)
2) tm structure print
tm_gmtoff: 0
tm_hour: 0
tm_isdst: 0
tm_mday: 10
tm_min: 0
tm_mon: 8
tm_sec: 0
tm_wday: 0
tm_yday: 0
tm_year: 101
Are there any other (easy and fast) ways to get time in seconds for my case?