Home  >  Article  >  Backend Development  >  PHP uses mktime() to get the timestamp of a certain period of time_PHP tutorial

PHP uses mktime() to get the timestamp of a certain period of time_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:13:30897browse

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 parameters can be left empty in order from right to left, and the empty parameters will be set to the corresponding current GMT value.
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.

Grammar mktime(hour,minute,second,month,day,year,is_dst)

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...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn