- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
最好的方法是什么,而不使用 MS COM 库将 OLE 日期时间格式转换为 boost 使用的 posix_datetime?
OLE 日期时间表示为 float 。
最佳答案
您必须手动执行...我找不到其他方法...
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)));
}
关于c++ - OLE 日期时间到 Posix_time,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5246140/
我正在尝试将 boost::posix_time::ptime 转换为特定的字符串格式(扩展 ISO),然后再转换回 boost::posix_time::ptime. 令人惊讶的是,它看起来像对于
我在尝试编译这段代码时遇到了这些奇怪的编译错误。 OutputHandler.h: #pragma once #include #include #include "FileNotAccessib
当我尝试使用以下行编译代码时:(我正在使用 boost 1.51,在 UBuntu 12.04 LTS 64 中使用 gcc 4.6.3位) #include dotFile *, std::v
我想将分钟数舍入到给定的步骤(15分钟)。像这样 "2002-01-20 23:35:59.000" -> "2002-01-20 23:30:00.000" "2002-01-20 23:00:59
我需要纳秒分辨率,我在文档中读到: http://www.boost.org/doc/libs/1_53_0/doc/html/date_time/details.html#date_time.bui
我使用以下方法通过 boost::posix_time 检索包含当前时间的字符串: wstring TimeField::getActualTime() const { // Defined el
最好的方法是什么,而不使用 MS COM 库将 OLE 日期时间格式转换为 boost 使用的 posix_datetime? OLE 日期时间表示为 float 。 最佳答案 您必须手动执行...我
有人能解释一下为什么我们需要从 boost::posix_time::ptime 中减去 boost::gregorian::date(1970,1,1) 以获得 POSIX 时间符号(即自 1970
我有一组函数,允许我根据特定格式将 ptime 转换为字符串并将字符串转换为 ptime。 这很好用,直到我需要使用毫秒修饰符(%f)。 转换为 String 工作正常: std::string st
boost::posix_time::ptime 是固定大小的吗? 我想用它来替换一些自定义的时间类型垃圾,但它需要进入的类是预分配内存池的一部分,并且必须是固定大小。 如果是这样,我在哪里可以找到保
我试图在整个互联网上找到答案。我需要以微秒为单位的秒级时间戳。 boost::posix_time::ptime now = boost::posix_time::microsec_clock::lo
奇怪的是, std::cout << boost::posix_time::from_iso_string("20120927T062299");// 99 seconds! yields 2012-
我有以下代码从 posix_time 获取 UNIX 时间 boost::posix_time::ptime time1(boost::gregorian::date(9999,12,31)); bo
当我在我的 C++ 代码中包含 boost/date_time/posix_time/posix_time.hpp 时出现以下编译错误 /usr/include/boost/date_time/dat
我正在从 PostgreSQL 数据库中读取时间戳字段。时间戳列定义为: my_timestamp TIMESTAMP WITH TIME ZONE DEFAULT NOW() 从数据库中读取时,我将
这不是问题,只是出于好奇。我想知道当使用其他语言的 dateTime 实现的类似操作只有 3 或 4 行时,我必须编写多少代码才能实现此目的。 所以我得到的是作为字符串的时间戳,即:06-Feb-20
我正在尝试从文本文件中解析日期时间。时间戳具有微秒精度,但由于我无法控制的历史原因,它们是使用冒号而不是点来分隔小数秒部分创建的,例如: 2015/05/05 03:10:43:537408 代替 2
我正在尝试对两个起初看起来并不难的问题给出答案。Q1:如何获取 UTC.Now() 和给定日期之间经过的秒数?A1:就像下面的代码一样!Q2:我如何确定自上次“完整”秒以来已经过去了多少小数秒?我想打
我有一个像“2012-03-28T08:00:00”这样的格式化字符串。我想获取年、月(字符串格式)、日期、小时、分钟、秒和日(字符串格式)。谁能建议我在 boost 中使用最简单的方法。 谢谢 最佳
我正在使用 boost::posix_time::ptime 来测量我的模拟运行时间和其他东西。 假设 boost::posix_time::ptime start, stop; boost::pos
我是一名优秀的程序员,十分优秀!