date - 回历日期公式
问题描述
将“自纪元以来的时间”戳记转换为1525249213
回历日期(年-月-日)的公式是什么?
我知道有一天会有误差,这对我来说是可以的。
解决方案
我发现的算法是将日期转换为儒略日期,然后将儒略日期转换为回历。
PS我不记得我在哪里找到的。我不对使用此代码的任何错误或错误准确性或后果 bla bla bla 负责。
unsigned long gregorian_to_julian(const int gyear, const int gmonth, const int gday) {
if (gmonth < 3) {
gyear -= 1;
gmonth += 12;
}
auto a = int(gyear / 100.0f);
auto b = (gyear == 1582 && (gmonth > 10 || (gmonth == 10 && gday > 4)) ? -10 :
(gyear == 1582 && gmonth == 10 ? 0 :
(gyear < 1583 ? 0 : 2 - a + int(a / 4.0f))));
return int(365.25f * (gyear + 4716)) + int(30.6001f * (gmonth + 1)) + gday + b - 1524;
}
std::array<int,3> julian_to_hijri(const unsigned long julian_datestamp) {
std::array<int,3> result;
auto y = 10631.0f / 30.0f;
auto epoch_astro = 1948084;
auto shift1 = 8.01f / 60.0f;
auto z = julian_day - epoch_astro;
auto cyc = int(z / 10631.0f);
z = z - 10631 * cyc;
auto j = int((z - shift1) / y);
z = z - int(j * y + shift1);
result[0] = 30 * cyc + j; //Hijri Year
result[1]= int((z + 28.5001f) / 29.5f); //Hijri Month
if (result[1] == 13) {
result[1]= 12;
}
result[2] = z - int(29.5001f * result[1]- 29);// Hijri day
return result;
}
PS 结果回历日期会有 +-1 一日误差。
推荐阅读
- node.js - UnhandledPromiseRejectionWarning 测试失败
- python - 从另一个列表中减去一个列表的所有元素的最简单方法是什么?
- javascript - 单击新选项后,如何清除上一个选项的结果。它不断将自己附加到上一个选项
- android - 将事件添加到 Outlook 日历
- python-3.x - 为什么 I/O 与多线程 Python 应用程序中的计算不重叠?
- html - 使用 office url referrer 直接从浏览器打开 word 文件
- mysql - 我如何从数据库中获取图像以在 laravel 中查看文件
- c# - 如何获取弹出窗口或对话框的窗口标题、进程 ID?
- c# - 随机选择文档
- java - Android - 在 JUnit/Espresso 测试中更改语言环境以使用规则生成应用屏幕截图