0

我正在尝试在 PHP 中为第二天生成一个随机的 unix 时间戳。谁能指出我如何做到这一点的正确方向?

谢谢!坦率

4

2 回答 2

3

如果您的意思是上午 12:00 到晚上 11:59 之间的随机时间戳,您可以执行以下操作:

$tomorrow0000 = mktime(0, 0, 0, date('n'), date('d')+1, date('Y')); // midnight tomorrow
$tomorrow2359 = mktime(0, 0, 0, date('n'), date('d')+2, date('Y')) - 1; // midnight next day minus 1 second

$random = mt_rand($tomorrow0000, $tomorrow2359);
于 2013-06-23T12:36:18.130 回答
0

我认为这可以工作:

$tomorrow_time = strtotime("tomorrow") + rand(0, 86400);

基本上,我得到明天的午夜时间,然后从 0 到 86400(24 小时)添加随机秒

于 2018-11-07T17:41:52.820 回答