头像

php获取当前时间,计算一天,一周,一月,一年后的时间

2019-11-22 13:44:25 来源:PHP代码   浏览()   评论 ( 0 )   

  header("Content-type: text/html; charset=utf-8");
  echo '当前时间加一个月,一个礼拜,一天,一小时,15分钟这里测试';
  echo '当前时间是'.date('Y-m-d H:i:s',time());
  $now = date('Y-m-d H:i:s',time());
  echo '当前时间加长期这里就加10年吧是:'. date("Y-m-d H:i:s",strtotime("+10years",strtotime($now)));
  echo '当前时间加一年是:'. date("Y-m-d H:i:s",strtotime("+1years",strtotime($now)));
  echo '当前时间加一月是:'. date("Y-m-d H:i:s",strtotime("+1months",strtotime($now)));
  echo '当前时间加一周是:'. date("Y-m-d H:i:s",strtotime("+7days",strtotime($now)));
  echo '当前时间加一周是:'. date("Y-m-d H:i:s",strtotime("+1weeks",strtotime($now)));
  echo '当前时间加1小时是:'. date("Y-m-d H:i:s",strtotime("+1hours",strtotime($now)));
  echo '当前时间加15分钟是:'. date("Y-m-d H:i:s",strtotime("+15minutes",strtotime($now)));
  echo '当前时间加1分钟是:'. date("Y-m-dH:i:s",strtotime("+1minutes",strtotime($now)));

  //时间比较,转成时间戳

  //假如有效时间是1小时

  

  $nowtime = strtotime("now"); //或者 $nowtime = data('Y-m-d H:i:s',time());
  $endtime = strtotime(date("Y-m-d H:i:s",strtotime("+1hours",strtotime($now))));
  print_r($nowtime);
  print_r($endtime);
  echo '从而可以比较2两时间来判断是否执行某个时间';


标签:
声明:转载请注明来源(PHP代码)并保留原文链接:http://www.phpdaima.com//wenzhang-135.html
广告不存在
评论0

后面还有条评论,点击查看>>

温馨提示:为规范评论内容,垃圾评论一律封号...