0
0

More than 3 years have passed since last update.

【PHP】時間取得

Last updated at Posted at 2020-07-01

タイムスタンプから時効への返還とかtime()とかstrtotime()とかの役割をすぐ忘れるので、備忘録。

date(タイムスタンプ→日時)

日付の文字列を返してくれる。
タイムスタンプを文字列の日時に直してくれる。

現在時刻取得

print date('Y/m/d');//20xx/x/x/

タイムスタンプを文字列に変換する

$timeStamp=time();
print date('Y/m/d h:i:s',$timeStamp);

strtotime(日時→タイムスタンプ)

英文形式の日付を Unix タイムスタンプに変換する。
日付をタイムスタンプ

echo strtotime("now"), "\n";
echo strtotime("10 September 2000"), "\n";
echo strtotime("+1 day"), "\n";
echo strtotime("+1 week"), "\n";
echo strtotime("+1 week 2 days 4 hours 2 seconds"), "\n";
echo strtotime("next Thursday"), "\n";
echo strtotime("last Monday"), "\n";

time

現在のUnixタイムスタンプを返す。

print time();
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0