Skip to content

Instantly share code, notes, and snippets.

@AtsushiSuzuki
Created December 1, 2015 08:52
Show Gist options
  • Save AtsushiSuzuki/e5a1c1c2d2b0add48bfb to your computer and use it in GitHub Desktop.
Save AtsushiSuzuki/e5a1c1c2d2b0add48bfb to your computer and use it in GitHub Desktop.
PHPで和暦の計算
<?php
function formatDate($time, $format = 'Y年M月d日 H時m分s秒', $timezone = null) {
$cal = IntlCalendar::createInstance($timezone, 'ja_JP@calendar=japanese');
$fmt = IntlDateFormatter::create('ja_JP', null, null, null, $cal, $format);
return $fmt->format($time);
}
echo formatDate(time(), 'Gy年') . PHP_EOL;
// => 平成27年
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment