PHP determines two methods for a specified period of time

  • 2021-01-25 07:22:59
  • OfStack

1. Include hour and minute judgments


date_default_timezone_set("Asia/Shanghai");
$time = intval (date("Hi"));
if ($time > "800" && $time < "1130") {
  // code
}


2. Only judge hours


date_default_timezone_set("Asia/Shanghai");
if(date('G')<8 || date('G')>17)
{
  // code
}$h = intval(date("H")); 
if ($h > 23 || $h < 7) {
 echo ' This is the first 1 A task ';
} else {
 echo ' This is the first 2 A task ';
}

3. php judges statements by time division and time period


<?php 
date_default_timezone_set('PRC');// Set the time zone, where PRC For "People's Republic of China" 
$j=date("H:i"); Gets the time for the current hour and minute 
$h=strtotime($j);// Gets the time timestamp for the current hour and minute 
$z=strtotime('00:00');// Gets the specified minute timestamp, 00:00
$x=strtotime('00:29');// Gets the specified minute timestamp, 00:29
if($h>$z && $z<$x){
  echo ' Display time is 00:00 to 00:29 Points between ';
}
?>


Related articles: