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:
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
输出:
1138618081
Mon January 30 2006
例子 2
输出:
Now: 2005-03-30
Next Week: 2005-04-07