C++ 旧时间到现在的时间(以小时为单位)
c++ old time to now time in hours
嗨,我如何获得创建文件的时间与现在之间的差异并将其转换为小时。
for (unsigned i = 0; i < strpokenter code herele.size(); i++)
{
const char * conv_my_str = strpole[i].c_str();
stat(conv_my_str, & stbuf);
oldate = ctime( & stbuf.st_atime);
cout << oldate;
time( & rawtime);
nowdate = ctime( & rawtime);
cout << nowdate;
getchar();
}
我通过自动和计时来解决它,但是如果您想要小时,则需要分钟示例,因为我首先说过,您可以轻松地在代码中将分钟更改为小时。
auto now = std::chrono::duration_cast<std::chrono::minutes>(actTime - std::chrono::system_clock::from_time_t(stbuf.st_ctime)).count();
看看GetFileTime
这两个链接可能会在这里和这里有所帮助
如果我猜对了,问题是关于以小时为单位表示增量时间......因此,您在读取文件的创建时间或实际时间时不会遇到麻烦...... 所以你可以去:
#include <iostream>
#include <string>
std::string getDuration(const long ms) {
int seconds = (int)(ms / 1000) % 60;
int minutes = (int)((ms / (1000 * 60)) % 60);
int hours = (int)((ms / (1000 * 60 * 60)) % 24);
return "H:" + std::to_string(hours) +",M:"+ std::to_string(minutes)+",S:"+ std::to_string(seconds);
}
int main() {
long ms = 60 * 1000;
std::cout << "Duration: " << getDuration(ms) << std::endl;
return 0;
}
相关文章:
- C++为构建时间获取QDateTime的可靠方法
- 时间转换为 24 小时格式 cpp
- 格式化的时间字符串在解析为time_point时会产生小时差异
- C++ 旧时间到现在的时间(以小时为单位)
- 仅将纪元字符串保存到 mysql 日期时间年/月/日,但没有小时分钟秒
- 使用提升解析日期时间字符串:采用个位数小时格式
- 比较12小时格式时间
- 将时间转换为小时、分钟和秒
- 12小时到24小时的时间转换
- 解析日期字符串以从时间戳中删除小时、分钟和秒
- 将年龄在几年,小时,几分钟和秒的时间内转换
- BOOST LOCAL_DATE_TIME:如何设置特定时间信息(小时,最小值和SEC)
- 返回的C 时间为两个小时
- C++ :将时间从 12 小时转换为 24 小时的类,无法识别自己的数据字段
- 将十进制时间转换为小时和分钟,以便以C++显示
- 查看时间戳是否在特定小时之间
- 获取当前小时unix时间戳
- 两个时间之间经过的时间,格式为24小时hh:mm:ss
- 在精确的时间运行代码,每小时运行一次
- 在c++中将24小时时间转换为整数值