首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >升压微秒

升压微秒
EN

Stack Overflow用户
提问于 2014-05-19 22:15:55
回答 1查看 947关注 0票数 1

我正在做以下工作

代码语言:javascript
运行
复制
using namespace boost::posix_time;
ptime epoch = time_from_string("1970-01-01 00:00:00.000");
ptime other = time_from_string("2011-08-09 17:27:00.000.000");
time_duration const diff = other - epoch;
long long ms = diff.total_microseconds();
cout<<"diff is"<<ms<<endl;

我得到的回声是1312910820000000

然后,当我将另一个页面更改为

代码语言:javascript
运行
复制
ptime other = time_from_string("2011-08-09 17:27:00.000.100");

我也有同样的回声,为什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-05-19 22:26:11

格式不正确,您有太多的.分隔符:住在Coliru

代码语言:javascript
运行
复制
#include <iostream>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/date_time/posix_time/posix_time_io.hpp>

int main() 
{
    using namespace boost::posix_time;
    ptime epoch = from_time_t(0);
    ptime other = time_from_string("2011-08-09 17:27:00.000000");
    std::cout << "diff is " << (other - epoch).total_microseconds() << std::endl;

    other = time_from_string("2011-08-09 17:27:00.00001");
    std::cout << "diff is " << (other - epoch).total_microseconds() << std::endl;
}

打印

代码语言:javascript
运行
复制
diff is 1312910820000000
diff is 1312910820000010
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23748075

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档