The traditional Japanese calendar consists of eras based on the reigning emperors. The imperial date format is required for some government documents and appl
You just have to use IntlDateFormatter::parse
:
<?php
$formatter = new IntlDateFormatter(
'ja_JP@calendar=japanese',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'Europe/Madrid',
IntlDateFormatter::TRADITIONAL,
'Gy' //Age and year (regarding the age)
);
$r = $formatter->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