This article will introduce how to get the timestamp of a certain period of time in PHP. It mainly uses time and mktime to operate. Friends in need can take a look.
The code is as follows
代码如下 |
复制代码 |
$y=date("Y",time());
$m=date("m",time());
$d=date("d",time());
$start_time = mktime(9, 0, 0, $m, $d ,$y);
$end_time = mktime(19, 0, 0, $m, $d ,$y);
$time = time();
if($time >= $start_time && $time <= $end_time)
{
// do something....
}
|
| Copy code
|
$y=date("Y",time());
$m=date("m",time());
代码如下 |
复制代码 |
$start_time = mktime(9, 0, 0, date("m"), date("d") ,date("Y")); |
$d=date("d",time());
$start_time = mktime(9, 0, 0, $m, $d ,$y);
$end_time = mktime(19, 0, 0, $m, $d ,$y);
$time = time();
if($time >= $start_time && $time <= $end_time)
{
// do something....
}
There is a place above that we can change
Introduction to mktime function
The mktime() function returns the Unix timestamp of a date.
The argument always represents a GMT date, so is_dst has no effect on the result.
| The parameters can be left empty in order from right to left, and the empty parameters will be set to the corresponding current GMT value.
Grammar
mktime(hour,minute,second,month,day,year,is_dst)
Parameter Description
hour optional. Specified hours.
minute is optional. Specified minutes.
second is optional. Specifies seconds.
month is optional. Specifies the numeric month.
day is optional. Specify days.
year is optional. Specified year. On some systems, legal values are between 1901 - 2038. However, this limitation no longer exists in PHP 5.
is_dst Optional. Set to 1 if the time is during Daylight Saving Time (DST), 0 otherwise, or -1 if unknown.
As of 5.1.0, the is_dst parameter is deprecated. Therefore the new time zone handling features should be used.
http://www.bkjia.com/PHPjc/629178.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/629178.htmlTechArticleThis article will introduce how to get the timestamp of a certain period of time in PHP, mainly using time and mktime. Operation, friends in need can take a look. The code is as follows. Copy the code $y=date(Y...