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.
Asked
Active
Viewed 269 times
1 Answers
1
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.

jspit
- 7,276
- 1
- 9
- 17