int64 时间计算(C++)
int64 time calculations in C++
我正在研究与C++相关的代码。
FILETIME ftTime;
GetSystemTimeAsFileTime(&ftTime);
struct DateTime
{
unsigned int dwLowDateTime;
unsigned int dwHighDateTime;
};
DateTime myTime;
myTime.dwHighDateTime = (unsigned int)ftTime.dwHighDateTime;
myTime.dwLowDateTime = (unsigned int)ftTime.dwLowDateTime;
ussigned __int64 AsUInt64_t
unsigned __int64 myInt64Time = *(unsigned __int64*)&myTime;
// I have Getstring format from date time some thing like this below
Format() {
SYSTEMTIME systemTime;
FileTimeToSystemTime(&fileTime, &systemTime);
const char* formatString = "%04d-%02d-%02d %02d:%02d:%02d.%03d";
// I have few variable declartions to be used for snprintf which is not mentioned here.
apiResult = _snprintf_s(pBuffer, sizeOfBuffer, count, formatString, systemTime.wYear, systemTime.wMonth, systemTime.wDay, systemTime.wHour, systemTime.wMinute, systemTime.wSecond, systemTime.wMilliseconds);
}
DateTime startTime = now(); // some how I am getting latest time here.
sleep(5s); // sleeping for 5 seconds.
DateTime endTime = now(); // i.e., after 5 seconds.
std::cout << "nOn Start Time:" << startTime.Format() << std::endl;
std::cout << "On End Tme: " << endTime.Format() << std::endl;
std::cout << "On Start Read " << *(unsigned __int64*)&startTime << std::endl;
std::cout << "On End Read " << *(unsigned __int64*)&endtime<< std::endl;
///////////////////
对于上面的输出如下。
On Start Time:2012-06-18 09:45:03.180
On End Time :2012-06-18 09:45:08.183
// Int Int64 I am getting as below
On Start Read : 129844863031802858
On End Read : 129844863081832935
我的问题是我想根据给定的间隔将边界划分为相等的间隔,例如每个间隔为 2 秒。我该怎么做?
上限(范围/间隔)间隔。
例如,开始:12:00:00:0000,结束为 12:01:52:00099。间隔是 16 秒,然后我们有 7 个间隔。
unsigned __int64 interval =16;
如果我使用上面的逻辑 int 如果我做(*(unsigned __int64*)&endtime - *(unsigned __int64*)&startTime) / interval)
,我没有得到 7 ?我该如何解决?
FILETIME
结构包含一个 64 位值,表示自 1601 年 1 月 1 日 (UTC) 以来的 100 纳秒间隔数。
检查此链接: 文件时间结构
因此,减去两个FILETIME
变量会得到以纳秒 (nS) 为单位的时间差。
将其除以 16(秒)不会给你你想要的。
除以 16 * 10^9 或使用为您执行此数学运算并返回时差(以秒为单位difftime
API(链接)。
相关文章:
- 为什么"do while"循环不断退出,即使条件计算结果为 false?
- 递归函数计算序列中的平方和(并输出过程)
- (C++)分析树以计算返回错误值的简单算术表达式
- 我的字符计数代码计算错误.为什么
- 在计算中使用二的幂有多有利可图
- 如何计算文件中的"columns"数?
- 计算排序向量的向量中唯一值的计数
- 如何使用 std::累积在 C++ 中计算总和立方体
- 使用Qt C++计算类似Git的SHA1哈希
- OpenCV C++.快速计算混淆矩阵
- cpp二进制搜索问题,计算给定数组中输入元素的出现次数
- C++如何计算用户输入的数字中的偶数位数
- 如何计算数据类型的范围,例如int
- 类似枚举的计算常量
- 计算每个节点的树高,帮助我解释这个代码解决方案
- 多个If语句与使用逻辑运算符计算条件的单个语句的比较
- 计算缩放多边形的比例,得到给定的多边形面积
- 在C++中如何在没有pow的情况下进行基础计算
- 计算平均值,不包括上次得分
- 如何计算多映射中重复对的数量