首页 > 解决方案 > 如何将儒略天数转换为儒略日期?44332 到 2021 年 5 月 17 日?

问题描述

我能够将常规日期(例如 05/19/2021)转换为儒略日期编号 44334(自 1990 年以来经过的天数)。

但是,我现在需要做相反的事情,我只是不知道该怎么做。

你能帮我解释一下这里的逻辑吗?

标签: c++

解决方案


You can use date.h or its C++20 implementation in case you already use it.

using namespace date;
using namespace date::literals;

This will do the trick.

year_month_day ymd(1990_y/01/01); // Create a date object. '_y' is a literal like 'f' for float which comes with `date::literals` or `chorno::literals`.
sys_days total_days = (sys_days)ymd; // Convert it to a time_point.
total_days += days(44334); // Add the days.
year_month_day later = total_days; // Convert it back to an object.

I found help here: std::chrono add days to current date


推荐阅读