Converting traditional Japanese era year into Gregorian year

前端 未结 1 1404
余生分开走
余生分开走 2021-01-25 14:51

The traditional Japanese calendar consists of eras based on the reigning emperors. The imperial date format is required for some government documents and appl

1条回答
  •  深忆病人
    2021-01-25 15:24

    You just have to use IntlDateFormatter::parse:

    format(strtotime('2012-01-01 Europe/Madrid'));
    echo "Age in Japanese: $r\n";
    $time = $formatter->parse($r);
    $gregCalendar = IntlCalendar::createInstance('Europe/Madrid', 'ja_JP');
    $gregCalendar->setTime($time * 1000);
    $r2 = IntlDateFormatter::formatObject($gregCalendar, 'Gy');
    echo "And back: $r2\n";
    

    gives:

    Age in Japanese: 平成24
    And back: AD2012
    

    0 讨论(0)
提交回复
热议问题