计算农历日期

发布于 2025-02-08 10:13:29 字数 51 浏览 1 评论 0原文

我想找出使用​​PHP的特定年份的农历新年日期。在2022年,我预计2022年2月1日。

I want to find out the Chinese New Year date for a specific year using PHP. For the year 2022 I expect February 1st, 2022.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

意犹 2025-02-15 10:13:29

使用 intldateformatter 这很容易做到。

$year = 2022;
$formatter = new IntlDateFormatter(
    'zh-CN@calendar=chinese',
    IntlDateFormatter::SHORT,
    IntlDateFormatter::NONE,
    'Europe/Berlin',
    IntlDateFormatter::TRADITIONAL
);
$timeStamp = $formatter->parse($year.'/01/01');
$dateTime = date_create()->setTimeStamp($timeStamp);
echo $dateTime->format('j F Y');  //1 February 2022

3v4l.org

This is very easy to do with the IntlDateFormatter.

$year = 2022;
$formatter = new IntlDateFormatter(
    'zh-CN@calendar=chinese',
    IntlDateFormatter::SHORT,
    IntlDateFormatter::NONE,
    'Europe/Berlin',
    IntlDateFormatter::TRADITIONAL
);
$timeStamp = $formatter->parse($year.'/01/01');
$dateTime = date_create()->setTimeStamp($timeStamp);
echo $dateTime->format('j F Y');  //1 February 2022

Try it yourself with 3v4l.org.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文