使用Boost或STD在特定时区中获取当前的本地时间
Use boost or std to get the current local time in a specific timezone
是否可以使用boost库或std在不知道偏移的情况下将当前时间获取当前时间?
?例如:"欧洲/罗马"的当地时间是什么?
这是一个单线,霍华德·辛南特(Howard Hinnant
#include "date/tz.h"
#include <iostream>
int
main()
{
std::cout << date::make_zoned("Europe/Rome", std::chrono::system_clock::now()) << 'n';
}
这个只是为我输出:
2017-11-29 16:24:32.710766 CET
检查以下内容:https://theboostcppplibraries.com/boost.datetime-location-dipperent-times
#include <boost/date_time/local_time/local_time.hpp>
#include <iostream>
using namespace boost::local_time;
using namespace boost::posix_time;
using namespace boost::gregorian;
int main()
{
time_zone_ptr tz{new posix_time_zone{"CET+1"}};
ptime pt{date{2014, 5, 12}, time_duration{12, 0, 0}};
local_date_time dt{pt, tz};
std::cout << dt.utc_time() << 'n';
std::cout << dt << 'n';
std::cout << dt.local_time() << 'n';
std::cout << dt.zone_name() << 'n';
}
输出:
2014-May-12 12:00:00
2014-May-12 13:00:00 CET
2014-May-12 13:00:00
CET
相关文章:
- C++为构建时间获取QDateTime的可靠方法
- c++ 11 如何获取系统时间?
- 获取 QInputEvent 在 Qt 4.8 中被放入 QEventLoop 队列时的时间戳
- 如何以毫秒为单位获取开始时间和 now() 之间的毫秒差异(以 C++为单位?
- 如何从远程 SFTP 服务器获取 HH-MM-SS 时间戳格式的文件列表
- 如何在 c++ stl 中获取列表中被推回的元素的地址,在常量时间内?
- 如何在 for 循环中的特定时间内获取要打印的额外值
- 如何以" Safe "的方式获取 C++ 中的当前时间
- C++程序以获取当前时间
- 为什么在C++中获取日期和/或时间如此复杂?
- 在 c++ 中获取 X 毫秒前的时间戳
- 如何获取两个时间点之间的时间
- 使用C++中的put_time以毫秒精度获取当前时间
- 获取合成时间C++
- 注册表-获取值(而不是键)上次更改的时间和键创建日期
- 如何在给定时钟偏移的情况下正确获取时间
- 从具有不同曝光时间的图像中获取HDR图像
- 如何在Mac OSX中获取真实的日历微秒时间(自1970年以来的纪元)?
- 通过修改时间获取目录中的文件
- 有没有办法通过程序在特定时间获取文件部分加载内容的大小C++