无法添加到 php 中的当前时间
Unable to add to current time in php
我无法向当前日期添加随机天时分秒。
这是我的代码-
$randnos=rand(0,30);
$randhrs=rand(00,24);
$randmin=rand(00,60);
$randsec=rand(00,60);
$newTime = date("d/m/Y H:m:s",strtotime(" +'.$randnos.' days" . " +'.$randhrs.' Hours". " +'.$randmin.' minutes". " +'.$randsec.' seconds"));
update_post_meta($post_id,'test',$newTime);
在 strtotime()
中使用的 string
中的问题。
$randnos=rand(0,30);
$randhrs=rand(00,24);
$randmin=rand(00,60);
$randsec=rand(00,60);
$str = ' +'.$randnos.' days +'.$randhrs.' Hours +'.$randmin.' minutes +'.$randsec.' seconds';
$newTime = date("d/m/Y H:m:s",strtotime($str));
先用随机数据创建字符串,然后插入strtotime()
。
你的引号全乱了。
$randnos=rand(0,30);
$randhrs=rand(00,24);
$randmin=rand(00,60);
$randsec=rand(00,60);
$newTime = date("d/m/Y H:m:s",strtotime("+$randnos days +$randhrs hours +$randmin minutes +$randsec seconds"));
update_post_meta($post_id,'test',$newTime);
单行
echo date('Y-m-d h:i:s', strtotime('+' .rand(30, 60 * 60 * 24 * 3).' seconds'));
$randnos = rand(0,30);
$randhrs=rand(00,24);
$randmin=rand(00,60);
$randsec=rand(00,60);
$sec = $randsec + ($randmin * 60) + ($randhrs * 60 * 60 ) + ($randnos * 60 * 60 * 24);
$newTime = date("d/m/Y H:m:s",strtotime(date("r")) + $sec );
我无法向当前日期添加随机天时分秒。
这是我的代码-
$randnos=rand(0,30);
$randhrs=rand(00,24);
$randmin=rand(00,60);
$randsec=rand(00,60);
$newTime = date("d/m/Y H:m:s",strtotime(" +'.$randnos.' days" . " +'.$randhrs.' Hours". " +'.$randmin.' minutes". " +'.$randsec.' seconds"));
update_post_meta($post_id,'test',$newTime);
在 strtotime()
中使用的 string
中的问题。
$randnos=rand(0,30);
$randhrs=rand(00,24);
$randmin=rand(00,60);
$randsec=rand(00,60);
$str = ' +'.$randnos.' days +'.$randhrs.' Hours +'.$randmin.' minutes +'.$randsec.' seconds';
$newTime = date("d/m/Y H:m:s",strtotime($str));
先用随机数据创建字符串,然后插入strtotime()
。
你的引号全乱了。
$randnos=rand(0,30);
$randhrs=rand(00,24);
$randmin=rand(00,60);
$randsec=rand(00,60);
$newTime = date("d/m/Y H:m:s",strtotime("+$randnos days +$randhrs hours +$randmin minutes +$randsec seconds"));
update_post_meta($post_id,'test',$newTime);
单行
echo date('Y-m-d h:i:s', strtotime('+' .rand(30, 60 * 60 * 24 * 3).' seconds'));
$randnos = rand(0,30);
$randhrs=rand(00,24);
$randmin=rand(00,60);
$randsec=rand(00,60);
$sec = $randsec + ($randmin * 60) + ($randhrs * 60 * 60 ) + ($randnos * 60 * 60 * 24);
$newTime = date("d/m/Y H:m:s",strtotime(date("r")) + $sec );