You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native:寻求支持150年准确转换的回历转公历工具

回历转公历的可靠解决方案(支持超150年准确转换)

推荐本地库

  • luxon:基于Umm al-Qura日历(沙特官方回历标准)实现,支持的年份范围远超150年,转换精度可靠。React Native中可直接安装使用:
import { DateTime } from 'luxon';

// 回历1436年3月2日转公历
const hijriDate = DateTime.fromFormat('1436-03-02', 'yyyy-MM-dd', { zone: 'utc', calendar: 'islamic-umalqura' });
const gregorianDate = hijriDate.setCalendar('gregory').toFormat('yyyy-MM-dd');
console.log(gregorianDate); // 输出对应准确公历日期
  • hijri-converter:专注于回历与公历的精确转换,支持回历1300H至1500H的范围,完全覆盖150年需求,无冗余依赖:
import { hijriToGregorian } from 'hijri-converter';

// 参数为回历的年、月、日
const gregorian = hijriToGregorian(1436, 3, 2);
console.log(gregorian); // 返回 { year: 2015, month: 2, day: 20 }

备选API方案

若倾向于使用API,可选择基于权威历法数据源的服务,调用时指定采用Umm al-Qura标准,这类API会根据回历闰月规则自动调整月份天数,不会出现固定30天的误差。调用时传递回历的年、月、日参数即可获取准确公历结果。

关键注意事项

  • 优先选择基于Umm al-Qura日历的实现,这是目前最广泛认可的高精度回历标准,能避免转换误差。
  • 在React Native中使用上述库时,无需额外复杂配置,直接安装后即可调用,注意匹配依赖版本避免冲突。

内容的提问来源于stack exchange,提问作者Yahya Ahmed

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 13:22:05