0

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.

DarkBee
  • 16,592
  • 6
  • 46
  • 58
jspit
  • 7,276
  • 1
  • 9
  • 17

1 Answers1

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