1
무엇이 최선의 방법, 부스터에 의해 사용되는 posix_datetime OLE 날짜 형식을 변환하는 데 사용하는 COM COM을 사용하지 않고?OLE 날짜 시간 Posix_time
OLE 날짜 시간은 부동 소수점 숫자로 표시됩니다.
무엇이 최선의 방법, 부스터에 의해 사용되는 posix_datetime OLE 날짜 형식을 변환하는 데 사용하는 COM COM을 사용하지 않고?OLE 날짜 시간 Posix_time
OLE 날짜 시간은 부동 소수점 숫자로 표시됩니다.
당신은 ... 수동으로 내가이 일을 발견했습니다 그냥 다른 방법이 그것을 할 수 없습니다해야 ... 정확성
boost::posix_time::ptime datetime_ole_to_posix(double ole_dt)
{
static const boost::gregorian::date ole_zero(1899,12,30);
boost::gregorian::days d(ole_dt);
boost::posix_time::ptime pt(ole_zero + d);
ole_dt -= d.days();
ole_dt *= 24 * 60 * 60 * 1000;
return pt + boost::posix_time::milliseconds(std::abs(ole_dt));
}
테스트 :
void datetime_ole_to_posix_test()
{
using boost::gregorian::date;
using namespace boost::posix_time;
/* http://msdn.microsoft.com/en-us/library/38wh24td.aspx */
BOOST_ASSERT(datetime_ole_to_posix(-1.0) == ptime(date(1899,12,29)));
BOOST_ASSERT(datetime_ole_to_posix(-1.25) == ptime(date(1899,12,29), hours(6)));
BOOST_ASSERT(datetime_ole_to_posix(0.0) == ptime(date(1899,12,30)));
BOOST_ASSERT(datetime_ole_to_posix(1.0) == ptime(date(1899,12,31)));
BOOST_ASSERT(datetime_ole_to_posix(2.25) == ptime(date(1900,01,01), hours(6)));
BOOST_ASSERT(datetime_ole_to_posix(2.0) == ptime(date(1900,01,01)));
BOOST_ASSERT(datetime_ole_to_posix(5.0) == ptime(date(1900,01,04)));
BOOST_ASSERT(datetime_ole_to_posix(5.25) == ptime(date(1900,01,04), hours(6)));
BOOST_ASSERT(datetime_ole_to_posix(5.5) == ptime(date(1900,01,04), hours(12)));
BOOST_ASSERT(datetime_ole_to_posix(5.875) == ptime(date(1900,01,04), hours(21)));
}