Skip to content

Instantly share code, notes, and snippets.

@alt-karate
Created June 21, 2021 05:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alt-karate/99831b8e5e6a2b35bfa857c12244e3a1 to your computer and use it in GitHub Desktop.
Save alt-karate/99831b8e5e6a2b35bfa857c12244e3a1 to your computer and use it in GitHub Desktop.
function custom_date(){
$date = get_the_time('Ymd');
$y = get_the_time('Y');
$m = get_the_time('n');
$d = get_the_time('j');
//昭和
if($date < 19890108){
if($y == 1926){
echo "昭和元年";
}
else{
echo "昭和" . ( $y - 1925 ) . "年";
}
}
//平成
elseif($date < 20190501){
if($y == 1989){
echo "平成元年";
}
else{
echo "平成" . ( $y - 1988 ) . "年";
}
}
//令和
else{
if($y == 2019){
echo "令和元年";
}
else{
echo "令和" . ( $y - 2018 ) . "年";
}
}
echo $m . "月" . $d ."日";
}
最終更新日を和暦表記にする場合は投稿日ではなく最終更新日を和暦表記にしたい場合は、「get_the_time()」を「get_the_modified_date()」に置き換えればOKです。
$date = get_the_modified_date('Ymd');
$y = get_the_modified_date('Y');
$m = get_the_modified_date('n');
$d = get_the_modified_date('j');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment