時間と数字のフォーマット
2014/07/02
教わったのでメモ。
・時間の整形
strtotime()
例)
$ymd = '2013-1-2';
echo date( 'Y-m-d', strtotime($ymd) );
結果)
2013-01-02
・リファレンス
http://php.net/manual/ja/function.strtotime.php
英文形式の日付を Unix タイムスタンプに変換する
英文形式ってのがよく分からないけど、下記が
サポートする日付みたい。
http://www.php.net/manual/ja/datetime.formats.php
------
・数字の整形
sprintf()
例)
$i = 1;
echo sprintf( "%02d", $i );
結果)
01
・リファレンス
http://php.net/manual/ja/function.sprintf.php
フォーマットされた文字列を返す
パラメーター等は下記がなんとなく分かりやすい
http://memopad.bitter.jp/w3c/php/func_string_sprintf.html
関連記事
-
-
php.iniを変更後にApacheを再起動しても反映されない場合の対応方法
先日AlmaLinux8系にChronyをインストールしてサーバの時刻同期を行っ ...
-
-
PHPでファイル書き込み時に「failed to open stream: HTTP~~」エラー
PHPでファイルを書き込む際に「failed to open stream: H ...
-
-
$_SERVER['PHP_SELF']に脆弱性あり
formのaction属性とかページングのリンクとかで、 <form ac ...
-
-
PHP8系で「Uncaught TypeError: Unsupported operand types」エラー対応方法
PHP8系で「Fatal error: Uncaught TypeError: ...
-
-
PHP7 / 8でBlowfishアルゴリズムを用いた暗号化と復号化方法
大分前にPHPでPearのCrypt_Blowfishパッケージを使用し、Blo ...