草庐IT

time_duration

全部标签

c++ - 使用 chrono 将 time_point 转换为特定持续时间

/*definitionofstartandendstd::chrono::time_pointstart;std::chrono::time_point_end;*/std::chrono::time_pointsomeclass::spf(){_end=std::chrono::system_clock::now();std::chrono::time_pointtime(_end-start);start=std::chrono::system_clock::now();returntime;}unsignedintsomeclass::secs(){returnstd::chr

如何在 macOS 中删除 Time Machine 本地快照

看到这个可用82GB(458.3MB可清除)顿时感觉清爽,之前的还是可用82GB(65GB可清除),安装个xcode都安装不上,费解半天,怎么都解决不了这个问题,就是买磁盘情理软件也解决不了。第一步:打开终端第二步:输入sudotmutillistlocalsnapshots/这个命令是查找出来备份的哪些,按照日期来记录。第三步:输入tmutildeletelocalsnapshots2023-10-31-152830删除这个备份。第四步:打开磁盘工具,查看存储空间是否被释放。参考文章:https://zhuanlan.zhihu.com/p/39689057?eqid=efb11378001

c++ - 如何用纪元前的 time_t 计算 C++ 中的时间差?

我想用我的简单程序做的是计算两个日期之间的秒数差。time_treferenceDate;time_tdateNow=time(0);structtmreferenceDateComponent={0};referenceDateComponent.tm_hour=0;referenceDateComponent.tm_min=0;referenceDateComponent.tm_sec=0;referenceDateComponent.tm_year=89;referenceDateComponent.tm_mon=11;referenceDateComponent.tm_mday

c++ - 使用 chrono::time_point 获取当前小时数和分钟数

我一直试图找到一个使用std::chrono的示例,它只获取一个chrono::time_point并将小时数和分钟数提取为整数。我有:std::chrono::system_clock::time_pointnow=std::chrono::system_clock::now();但我不知道如何提取小时和分钟(从午夜开始)?我正在寻找类似的东西:inthours=now.clock.hours(); 最佳答案 这是免费的,open-sourcedatelibrary这将为你做这件事。如果您想确切了解它是如何完成的,请随时检查代码。

c++ - 如何从 boost::posix_time::ptime 获取自纪元时间以来的毫秒数

我看过一些otheranswersonSO这表明我们可以通过从“其他”时间中减去纪元时间来获得以毫秒为单位的纪元时间,但是当我尝试时它不起作用:ptimeepoch=time_from_string("1970-01-0100:00:00.000");ptimeother=time_from_string("2011-08-0917:27:00.000");longdiff=(other-epoch).total_milliseconds();在这个阶段diff是-1349172576,它应该是一个正数,因为“其他”时间是2011年。有人知道是什么原因造成的吗?获取纪元以来的毫秒数的正

c++ chrono duration_cast 到毫秒结果以秒为单位

我想要自纪元以来的毫秒数。一个流行的解决方案如下所示(这里提出的这个问题的解决方案之一Gettimesinceepochinmilliseconds,preferablyusingC++11chrono)#include#includeintmain(){automillitime=std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count();std::cout通过调用g++来编译它,比如g++-std=c++11main.cpp-otimetest产生输出13726860

c++ - (伪)-行列式为零的 N×N 矩阵的逆

我想在我的GraphSlam中使用nxn矩阵的逆矩阵。我遇到的问题:.inverse()Eigen库(3.1.2)不允许零值,返回NaNLAPACK(3.4.2)库不允许使用零行列式,但允许零值(使用来自ComputingtheinverseofamatrixusinglapackinC的示例代码)Seldon库(5.1.2)由于某种原因无法编译有没有人成功实现了允许负数、零值和零行列式的nxn矩阵求逆代码?有什么好的库(C++)推荐吗?我尝试为GraphSlam计算以下omega:http://www.acastano.com/others/udacity/cs_373_autono

c++ - 使用 Visual Studio 获取 time_t 的最大值

我需要独立于以下代码工作平台:timevaltv;tv.tv_sec=std::numeric_limits::max();此代码在各种LinuxOS和MacOSX下都能正常工作。不幸的是,在Windows下,对于tv.tv_sec这将返回-1。然后我想像这样重新定义time_t:typedefinttime_t;这也不起作用,因为编译器现在提示:errorC2371:'time_t':redefinition;differentbasictypes我怎样才能让这段代码独立于平台运行? 最佳答案 tv.tv_sec=std::num

C++ 模板 : How to put nontype constraints in compiling time

假设我有以下模板templateclassFOO{....}事实上,我要求(I>=F)。如果有人误用FOOa;我希望提出一个编译错误。如何做到这一点?谢谢 最佳答案 一种方法可能是C++11的static_assert,它类似于assert,但在编译时检查:templateclassFOO{static_assert(I>=F,"IneedstobelargerorequaltoF");...}; 关于C++模板:Howtoputnontypeconstraintsincompiling

c++ - 不同类型的 std::chrono::duration 的 std::min

考虑以下代码://durationsarefromstd::chronoautoa=get_duration_1();//milliseconds,willvaryinfutureversionsautob=get_duration_2();//seconds,willvaryinfutureversionsautoc=std::min(a,b);它无法编译,因为编译器无法实例化std::min的正确版本因为参数类型不同。当然,现在可以使用std::min明确指定类型.在此代码的future版本中,类型会有所不同。在不知道确切持续时间类型的情况下执行此操作的通用方法是什么?