使用今天的日期获取随机时间

时间:2015-09-25 12:48:28

标签: php

我需要从今天起随机时间。我试过用这个

$today = date('YmdHi');
$startDate = date('YmdHi', strtotime('-0.5 days'));
$range = $today - $startDate;
$rand = rand(0, $range);
$smthing=$startDate + $rand;

return $smthing;

但它无法正常工作。

例如,我想生成今天的日期及其中的任何日期。

预期输出

  

2015:25:09 14:10:20

     

2015:25:09 08:12:26

     

2015:25:09 01:02:24

1 个答案:

答案 0 :(得分:3)

使用



if(isset($_POST['todotext'])) {

$chunk = $_POST['todotext']; 

$commentArray = explode(" ",$chunk);


.
.
.

$commentArray[$i]='<p class="pos"><img src="imgs/blank.png" width="40" height="40"><br>
                                           '.$commentArray[$i].'</p>';


$together = implode(" ",$commentArray);    

echo $together;

根据您的问题,它只会在当天生成时间间隔

相关问题