我正在尝试在PHP中生成第二天的随机unix时间戳。有人能指出我如何做到这一点的正确方向吗?
谢谢! 弗兰克
答案 0 :(得分: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);
答案 1 :(得分:0)
我认为这可行:
$tomorrow_time = strtotime("tomorrow") + rand(0, 86400);
基本上,我是明天的午夜时间,然后从0随机添加秒到86400(24小时)