LoginSignup
0
0

More than 1 year has passed since last update.

PHPでランダムな時間を生成

Last updated at Posted at 2022-06-30

PHP Ver8.1.3

DBにぶっこんだら0埋めしてくれそうだけど、これの出力値は0埋めされていません。

for($i = 0; $i < 5; $i++){
    $randomYmdhis = '2022' . '/' . '06' . '/' . rand(1, 30) . ' ' . rand(0, 23) . ':' .  rand(0, 59) . ':' . rand(0, 59);
    echo $randomYmdhis . "\n";
}
2022/06/19 20:12:27
2022/06/26 4:45:48
2022/06/7 7:57:11
2022/06/28 4:36:49
2022/06/1 11:24:47

時間計測(1000件)

$start = microtime(true);

for($i = 0; $i < 1000; $i++){
    $randomYmdhis = '2022' . '/' . '06' . '/' . rand(1, 30) . ' ' . rand(0, 23) . ':' .  rand(0, 59) . ':' . rand(0, 59);
    echo $randomYmdhis . "\n";
}

echo microtime(true) - $start;
0.0018651485443115

時間計測の記事参考

PHPの処理速度を計測

0
0
4

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