0
0

More than 3 years have passed since last update.

PHPのタイムスタンプについて

Posted at

学習記録

前提条件

・PHP version 5.4

UNIXタイムスタンプ

関数 概要         
ceil()           切り上げ
floot()           切り捨て
round()      四捨五入
round(a, '○')        aを小数○桁になるように四捨五入
mt_rand(a, b) aからbのランダム整数値を返す
max(a, b, c,...) ()内の最大値を返す
min(a, b, c,...) ()内の最小値を返す
M_PI 円周率
M_SQRT2 2の平方根

日時を扱う関数

builtin.php
//現在の秒数を表示する
echo time() . PHP_EOL;
//結果:1587889548

//年-月-日 曜日の表示
echo date('Y-m-d l', time()) . PHP_EOL;
//結果:2020-04-26 Sunday

//特定日時は時、分、秒、月、日、年の順で書く
echo date('Y-m-d l', mktime(0, 0, 0, 5, 1, 2020)) . PHP_EOL;
//2020-05-01 Friday

//日時のような文字列から UNIX タイムスタンプを作ることもできる
echo date('Y-m-d l', strtotime('2020-05-07')) . PHP_EOL;
//2020-05-07 Thursday

//足すこともできる
echo date('Y-m-d l', strtotime('2020-05-07 +1 day')) . PHP_EOL;
//2020-05-08 Friday
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