C++时区转换

#include <iostream>
#include "cctz/civil_time.h"
#include "cctz/time_zone.h"


// 时区转换库
// https://github.com/google/cctz

int test() {
    for (cctz::civil_day d(2016, 2, 1); d < cctz::civil_month(2016, 3); ++d) {
        std::cout << "Hello " << d;
        if (d.day() == 29) {
            std::cout << " <- leap day is a " << cctz::get_weekday(d);
        }
        std::cout << "\n";
    }

    cctz::time_zone nyc;
    cctz::load_time_zone("America/New_York", &nyc);

    // Converts the input civil time in NYC to an absolute time.
    const auto moon_walk =
        cctz::convert(cctz::civil_second(1969, 7, 20, 22, 56, 0), nyc);

    std::cout << "Moon walk in NYC: "
        << cctz::format("%Y-%m-%d %H:%M:%S %Ez\n", moon_walk, nyc);

    cctz::time_zone syd;
    if (!cctz::load_time_zone("Australia/Sydney", &syd)) return -1;
    std::cout << "Moon walk in SYD: "
        << cctz::format("%Y-%m-%d %H:%M:%S %Ez\n", moon_walk, syd);
}

参考

GitHub - google/cctz: CCTZ is a C++ library for translating between absolute and civil times using the rules of a time zone.


创作不易,小小的支持一下吧!

  • 5
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

码力码力我爱你

创作不易,小小的支持一下吧!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值