PHP mktime() function gets local timestamp

怪我咯
Release: 2023-03-07 14:06:02
Original
4512 people have browsed it

Use the mktime() function in PHP to convert a time into a UNIX timestamp.

The mktime() function returns a UNIX timestamp based on the parameters given. A timestamp is a long integer containing the number of seconds since the UNIX epoch (January 1, 1970) to a given time. Its parameters can be omitted from right to left. Any omitted parameters will be set to the current value of the local date and time. The syntax format of this function is as follows:

mktime(hour,minute,second,month,day,year,is_dst)
Copy after login

Parameter description :

hour Optional. Specified hours.

minute Optional. Specified minutes.

second 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 PHP 5.1.0, this parameter has been deprecated. The new time zone handling features should be used instead.)

PHP mktime() function gets local timestamp Note: The typical range of valid timestamps is 1901 GMT 12 January 13, 20:45:54~January 19, 2038, 03:14:07 (this range conforms to the minimum and maximum values ​​​​of 32-bit signed integers). In Windows systems, this range is limited to January 1970 1st ~ January 19th, 2038.

Localized timestamp example

This example uses the mktime() function to obtain the current time of the system. Since the timestamp is returned, the date() function must be used. Format it to output the date and time. The example code is as follows:

<?php
header("Content-type:text/html;charset=utf-8");    //设置编码

echo "mktime 函数返回的时间戳:".mktime()."<br/>";

echo "当前的日期为:".date("Y-m-d",mktime())."<br/>";

echo "当前的时间为:".date("H:i:s",mktime());

?>
Copy after login

The running result is as shown in the figure:

PHP mktime() function gets local timestamp

The above is our simple application of the mktime() function.

In PHP, a function is specially provided to obtain the current timestamp. In the next section, we will explain how to get the current timestamp.

The above is the detailed content of PHP mktime() function gets local timestamp. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!