作記録

記憶代わり

PHPのDateTimeのformat()メソッド表記一覧

<?php

date_default_timezone_set('Asia/Tokyo');
$now = new \DateTime('now');

//ISO8601形式(2020-03-04T21:42:24+09:00)
print($now->format(DateTime::ATOM));

//2020年
print($now->format('Y年'));

//03月
print($now->format('m月'));

//3月
print($now->format('n月'));

//Mar(3月)
print($now->format('M'));

//04日
print($now->format('d日'));

//4日
print($now->format('j日'));

//Wed(水曜日)
print($now->format('D'));

//06時(or 18時 つまり0がつく24時間形式の表示)
print($now->format('H時'));

//6時(or 18時 つまり0がつかない24時間形式の表示)
print($now->format('G時'));

//06時(or 06時 つまり0がつく午前/午後形式)
print($now->format('h時'));

//6時(or 6時 つまり0がつかない午前/午後形式)
print($now->format('g時'));

//05分
print($now->format('i分'));

//05秒
print($now->format('s秒'));

?>