Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 为明天生成随机unix时间戳';日期_Php_Date_Timestamp_Unix Timestamp - Fatal编程技术网

Php 为明天生成随机unix时间戳';日期

Php 为明天生成随机unix时间戳';日期,php,date,timestamp,unix-timestamp,Php,Date,Timestamp,Unix Timestamp,我试图用PHP为第二天生成一个随机的unix时间戳。有没有人能给我指出正确的方向,告诉我怎么做 谢谢! Frank如果您指的是上午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')) -

我试图用PHP为第二天生成一个随机的unix时间戳。有没有人能给我指出正确的方向,告诉我怎么做

谢谢!
Frank

如果您指的是上午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);

如果您指的是12:00am到11:59pm之间的随机时间戳,您可以执行以下操作:

$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);

我认为这是可行的:

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

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

我认为这可能有效:

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

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

“明天”并不是真正的随机秒。你在忙什么?我想在第二天以UNIX时间戳的形式生成一个随机时间。例如,第二天05:28,“明天”并不是随机的。你在忙什么?我想在第二天以UNIX时间戳的形式生成一个随机时间。例如,第二天05:28。一天不能保证有86400秒。。。!将夏令时问题合并到一段代码中。一天不能保证有86400秒。。。!将夏令时问题合并到一个代码块中。