Skip to content

Instantly share code, notes, and snippets.

@hidenorigoto
Last active August 14, 2024 07:57
Show Gist options
  • Save hidenorigoto/2327195 to your computer and use it in GitHub Desktop.
Save hidenorigoto/2327195 to your computer and use it in GitHub Desktop.
INTL(ICU)のIntlDateFormatterを使って和暦、曜日を表示
<?php
$date = new \DateTime();
// 平成◯◯年
$dateFormatter = \IntlDateFormatter::create(
"ja_JP@calendar=japanese",
\IntlDateFormatter::FULL,
\IntlDateFormatter::FULL,
"Asia/Tokyo",
\IntlDateFormatter::TRADITIONAL,
'Gyy年'
);
echo $dateFormatter->format($date);
// H◯◯年
$dateFormatter = \IntlDateFormatter::create(
"ja_JP@calendar=japanese",
\IntlDateFormatter::FULL,
\IntlDateFormatter::FULL,
"Asia/Tokyo",
\IntlDateFormatter::TRADITIONAL,
'GGGGGyy年'
);
echo $dateFormatter->format($date);
// 曜日
$dateFormatter = \IntlDateFormatter::create(
"ja_JP@calendar=japanese",
\IntlDateFormatter::FULL,
\IntlDateFormatter::FULL,
"Asia/Tokyo",
\IntlDateFormatter::TRADITIONAL,
'E'
);
echo $dateFormatter->format($date);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment