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

使用IntlDateFormatter将波斯历(Shamsi)转换为公历(Gregorian)失败的问题求助

使用IntlDateFormatter将波斯历(Shamsi)转换为公历(Gregorian)失败的问题求助

大家好,我最近在做波斯历转公历的功能,用PHP的IntlDateFormatter写了一段代码,但运行结果完全不符合预期,想请各位帮忙看看问题出在哪。

我写的代码如下:

function shamsi_to_miladi($date)
{
    $now = new DateTime($date);
    $IntlDateFormatter = new IntlDateFormatter(
        'en_US@calendar=gregorian',
        IntlDateFormatter::NONE,
        IntlDateFormatter::NONE,
        NULL,
        IntlDateFormatter::TRADITIONAL,
        "Y/MM/dd"
    );
    return $IntlDateFormatter->format($now);
}

echo shamsi_to_miladi("1402/08/17");

调用这个函数传入"1402/08/17"后,实际输出是1402/07/09,但正确的公历日期应该是2023/10/11。试了好几次都没解决这个问题,有没有懂的朋友能指点一下?

备注:内容来源于stack exchange,提问作者salehi

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.21 11:09:33