Using Howard Hinnant's free, open source, header-only library it can be done like this:
#include "date/date.h"
#include <iostream>
std::chrono::system_clock::time_point
to_chrono_time_point(double d)
{
using namespace std::chrono;
using namespace date;
using ddays = duration<double, days::period>;
return sys_days{January/1/1900} + round<system_clock::duration>(ddays{d});
}
int
main()
{
std::cout << date::format("%d.%m.%Y %H:%M\n", to_chrono_time_point(41274.043));
}
This simply converts the double
into a chrono::duration
with a representation of double
and a period of days
, then rounds that duration
into a system_clock::duration
, and finally adds that duration to 1.1.1900 00:00. The result is a std::chrono::system_clock::time_point
.
The std::chrono::system_clock::time_point
can be formatted with date::format
from the same library as shown. The output of this program is:
02.01.2013 01:01