gmtime给了我一些当地时间
gmtime is giving me some times localtime?
我在多线程环境中打印事件控制台是所有线程共享的静态互斥体。
问题是每一百或一千个事件随机发生一次,我得到的时间是当地时间,而不是UTC。
我只在Linux机器中看到过这个错误(使用g++构建),但在Windows中没有(使用VC++构建)。我不知道从哪里开始,知道吗?
void Publish(std::string source, std::string topic, std::string msg) NOEXCEPT {
console.lock();
std::time_t now = std::chrono::high_resolution_clock::to_time_t(*localTime);
char buf[50];
strftime(buf, sizeof (buf), "%Y-%m-%dT%H:%M:%S+00:00", gmtime(&now));
cout << buf << " " << source << " " << topic << " " << msg << endl;
cout.flush();
console.unlock();
}
struct tm * gmtime (const time_t * timer);
将time_t转换为tm作为UTC时间。此调用使用计时器指向的值来用表示相应时间的值填充tm结构,该值表示为UTC时间(即GMT时区的时间)。
这必须正常工作。然而,不确定这一点:
std::time_t now = std::chrono::high_resolution_clock::to_time_t(*localTime);
在多线程情况下,您的*localtime是否准确地给出了当前时间?它是一个共享变量吗?相反,你可以使用以下方法:
std::time_t now = time(0);
相关文章:
- C++为构建时间获取QDateTime的可靠方法
- 从持续时间构造std::chrono::system_clock::time_point
- 向量 <int> a {N, 0} 和 int arr a[N] = {0} 的时间复杂度有什么区别
- while循环中while循环的时间复杂度是多少
- 使用简单类型列表实现的指数编译时间.为什么
- 是否可以在编译时初始化数组,以便在运行时不会花费时间?
- 在已经使用Git的情况下减少编译时间
- 有没有一种方法可以创建一个带有哈希表的数据库,该哈希表具有恒定时间查找功能
- 如何将包含epoch时间的十六进制字符串转换为time_t
- 从文本文件中读取时钟时间和事件时间并进行处理
- 具有未知值时的时间复杂性
- 如何减少花费的时间
- C++在变量给定的指定时间内关闭电脑
- rcpp函数中的清理时间很长
- C++:floor unix时间戳到UTC月份
- 在纳秒中获得当地时间
- 如何使用C++和Boost查找纽约当地时间
- gmtime给了我一些当地时间
- 如何确定当前的当地时间是否为夏令时
- 如何获取当地时间并将其放入字符串中