• C++ Programming for Financial Engineering
    Highly recommended by thousands of MFE students. Covers essential C++ topics with applications to financial engineering. Learn more Join!
    Python for Finance with Intro to Data Science
    Gain practical understanding of Python to read, understand, and write professional Python code for your first day on the job. Learn more Join!
    An Intuition-Based Options Primer for FE
    Ideal for entry level positions interviews and graduate studies, specializing in options trading arbitrage and options valuation models. Learn more Join!

Std::Chrono - Wrong Epoch Time

I want to tranform a string to system time point and then calculate time since epoch but for some reason my program returns 5 hours for the below Unix time stamp,
C++:
void func()
{
    std::tm tm = {};
    std::stringstream ss("1970-01-01 00:00:00");
    ss >> std::get_time(&tm, "%Y-%m-%d %H:%M:%S");
    std::cout << std::put_time(&tm, "%c") << '\n';
    const auto output = std::chrono::time_point_cast<chrono::hours>(chrono::system_clock::from_time_t(mktime(&tm)));
    
    std::cout << output.time_since_epoch().count() << std::endl;
    
}

Screen Shot 2022-10-30 at 1.06.02 PM.png

Any help would be much appreciated , Thank you !
 
Back
Top