c++ - 如何在 boost 中获取当前的 UTC 日期?

标签 c++ date boost

鉴于这是一个基本问题,我想可能会有重复的问题,但我找不到任何问题。 我只是想从 boost 获取当前的 iso_date(比如 20110503)。

有什么建议吗?

最佳答案

我假设您正在寻找 Boost.Date_Time基于解决方案?

#include <locale>
#include <string>
#include <iostream>
#include <sstream>
#include <boost/date_time/gregorian/gregorian.hpp>

std::string utc_date()
{
    namespace bg = boost::gregorian;

    static char const* const fmt = "%Y%m%d";
    std::ostringstream ss;
    // assumes std::cout's locale has been set appropriately for the entire app
    ss.imbue(std::locale(std::cout.getloc(), new bg::date_facet(fmt)));
    ss << bg::day_clock::universal_day();
    return ss.str();
}

参见 Date Time Input/Output有关可用格式标志的更多信息。

关于c++ - 如何在 boost 中获取当前的 UTC 日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5863888/

相关文章:

c++ - Windows 中的麦克风列表(输入设备列表)

c++ - 无需键入整个容器定义即可引用迭代器的类型名称的有效方法?

c++ - 在 std::future::unwrap() 和 std::future::get() 中竞赛

sql - 在 SQL/ORACLE 中将列的数据类型 "varchar' 更改为 "DATE"

c++ - 获取 boost 命令行来解析我提供的数组而不是来自 main 的 argv - 模拟 argv

c++ - BOOST regex - 没有带有回调函数的 u32regex_replace() 原型(prototype)

c++ - Qt C++初始化列表困惑

python - 仅选择 future 日期 django 形式

python - 在 Python Pandas 中创建新的 QuarterEnd 列

c++ - operator<< with boost::variant 是如何实现的