The difference between time() and mktime() methods in php_php basics
The time() function returns the current time. The main function of the mktime() function is not to return the current time, but to format the time. Although writing mktime() alone without any parameters such as echo mktime() and echo time() has the same effect. But it's essentially different.
PHP mktime() function
PHP Date / Time function
Definition and usage
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 Optional. Specifies the numeric month.
day Optional. Specify days.
year 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.
Tips and Notes
Note: Before PHP 5.1, if the parameter of this function is illegal, it will return false.
Example
The mktime() function is very useful for date operations and verification. It can automatically correct out-of-bounds input:
echo(date(" M-d-Y",mktime(0,0,0,12,36,2001)));
echo(date("M-d-Y",mktime(0,0,0,14,1,2001)));
echo(date("M-d-Y",mktime(0,0,0,1,1,2001)));
echo(date("M-d-Y",mktime(0,0,0,1,1,99 )));
?>
Output:
Jan-05-2002
Feb-01-2002
Jan-01-2001
Jan-01-1999
PHP time() function
PHP Date /Time function
time() definition and usage
The time() function returns the Unix timestamp of the current time.
Grammar
time(void)
Parameter Description
void Optional.
Description
Returns the number of seconds since the Unix epoch (January 1, 1970 00:00:00 GMT) to the current time.
Tips and Notes
Tip: Since PHP 5.1, the timestamp of the time when the request was initiated is saved in $_SERVER['REQUEST_TIME'].
Example
Example 1
$t=time();
echo($t . "
");
echo(date("D F d Y",$t));
?>
输出:
1138618081
Mon January 30 2006
例子 2
$nextWeek = time() (7 * 24 * 60 * 60); // 7 days; 24 hours; 60 mins; 60secs
echo 'Now: '. date('Y-m-d') ."\n";
echo 'Next Week: '. date('Y-m-d', $nextWeek) ."\n";
?>
输出:
Now: 2005-03-30
Next Week: 2005-04-07

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 Chinese version
Chinese version, very easy to use

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.