しんちゃんのPHP入門道場
管理人:しんちゃんが独学でコツコツ学んだ経験を忘れないように秘かに記録しておいてるものです
※ まだ作成途中なので管理人の気分でレイアウトが変わります。ご勘弁を<(_ _)>

和暦変換

 
<?php

$time = mktime(0, 0, 0, 06, 05, 2008);
echo jdate("Vv年m月d日", $time);

function jdate($format, $timestamp = null)
{
    if($timestamp === null)
    {
        $timestamp = time();
    }

    $ymd = date("Ymd", $timestamp);
    $year = date("Y", $timestamp);

    if($ymd <= "19120729")
    {
        $label = "明治";
        $wareki = $year - 1867;
    }
    elseif($ymd >= "19120730" && $ymd <= "19261224")
    {
        $label = "大正";
        $wareki = $year - 1911;
    }
    elseif($ymd >= "19261225" && $ymd <= "19890107")
    {
        $label = "昭和";
        $wareki = $year - 1925;
    }
    elseif($ymd >= "19890108")
    {
        $label = "平成";
        $wareki = $year - 1988;
    }

    $ret = date($format, $timestamp);
    $ret = str_replace("V", $label, $ret);
    $ret = str_replace("v", $wareki, $ret);

    return $ret;
}

?>
 

Copyright (C) 2009 - 2018 しんちゃん All Rights Reserved.