We have written a code to get current timestamp in microseconds. The same code is working proper in ubuntu with clang16 and C++. When we test the same code in vxWorks RTP (CMake build system) we get incorrect values. Kindly help us to get required output in vxWorks as shown ubuntu’s output.
ubuntu output terminal
VxWorks terminal
#include <iostream>
#include <chrono>
#include <string>
namespace bhavik{
typedef char CHAR;
std::string epochToTime(void){
try{
const std::uint64_t epochTimeInMicroseconds = (std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch()).count());
std::cout << epochTimeInMicroseconds << std::endl;
std::string timeT;
const std::uint64_t microsecond = epochTimeInMicroseconds % 1000000U;
const time_t epochTimeInSec = (epochTimeInMicroseconds - microsecond) / 1000000U;
CHAR charTimeT[21];
(void)strftime(charTimeT, 20, "%d-%m-%Y %H:%M:%S", localtime(&epochTimeInSec));
timeT = charTimeT;
timeT = timeT + ":" + std::to_string(microsecond);
return timeT;
}
catch(const std::exception& ex){
std::cout << ex.what() << std::endl;
return "";
}
}
}
int main() {
std::string str=bhavik::epochToTime();
std::cout << str<< std::endl;
return 0;
}


You have not set time and date on your VxWorks, so you are seeing the default ones, and not an incorrect value. Setup the same time and date of your Ubuntu system on VxWorks or enable NTP on VxWorks if Ubuntu is running it and you will get the same results.