In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "how to query the current time in php". In daily operation, I believe many people have doubts about how to query the current time in php. The editor has consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts about "how to query the current time in php". Next, please follow the editor to study!
Five methods: 1, with "echo gmmktime ();" statement, can output the current GMT time; 2, with "echo mktime ();" statement; 3, with "echo microtime ();" statement, can output the current UNIX timest 4, with "echo time ();" and so on.
Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
In the date and time function, the acquisition of the UNIX timestamp is very important. The timestamp is a sequence of characters, which refers to the total number of milliseconds from 00:00:00 GMT on 01 / 01 / 1970 (08:00:00 Beijing time in 1970) to the present. Here are a few functions that get the current time.
1. Gmmktime ()
The gmmktime () function gets the UNIX timestamp of the GMT date. The syntax is as follows:
Gmmktime (hour,minute,second,month,day,year,is_dst)
The arguments to this function can be empty from right to left, and the empty arguments will be set to the corresponding current GMT value.
Examples of use are as follows:
Copy plain text copy echo gmmktime (); / / if no parameter is set, the current GMT time is obtained by default
The print result of executing the above program is:
2. Mktime ()
Mktime () can also get a UNIX timestamp for a date. The syntax is as follows:
Mktime (hour,minute,second,month,day,year,is_dst)
This function returns a UNIX timestamp based on the parameters given. The timestamp is a long integer that contains the number of seconds from the UNIX era to a given time.
Like the gmmktime () function, the parameters of this function can be omitted from right to left, and any omitted parameters are set to the current value of the date and time of the cost.
Examples of use are as follows:
Copy plain text copy echo mktime (); / / if no parameter is set, the current GMT time is obtained by default
The print result of executing the above program is:
3. Microtime ()
Microtime () gets the current UNIX timestamp and number of microseconds. The syntax is as follows:
Microtime (get_as_float)
Setting the value of the get_as_float parameter to true,microtime () returns a floating-point number; if there are no arguments, it returns a string in the format "msec sec", where sec is the number of seconds since the UNIX era and msec is the microsecond portion. Both parts of the string are returned in seconds.
Examples of use are as follows:
Copy plain text copy
The print result of the above procedure is as follows:
4. Time ()
The time () function returns the current UNIX timestamp. The syntax is as follows:
Time ()
The syntax of the time () function is relatively simple, and the examples are as follows:
Copy plain text copy
The print result of executing the above program is:
5. Getdate ()
Getdate () can get the date and time information. The syntax is as follows:
Getdate (timestamp)
This function returns an associative array array containing date information derived from timestamp. If no timestamp is given, it is considered to be the current local time (which is the same as the value of the time () function).
The key name units in the associative array returned by it are shown in the table.
The getdate () function returns an associative array key name description return value example the number of seconds seconds represents 0 to 59minutes minutes the number of 0 to 59hours hours the number of days of the month from 0 to 23mday the number of days of the week from 1 to 31wday the number of days of the week 0 (Sunday) to 6 (Saturday) the number of mon months represents the complete year represented by 1 to 12year4 digits such as 1999 or 2019yday The number of a few days represents the full text of the day from 0 to 365weekday and the full text representation of the month from Monday to Sundaymonth For example, the number of seconds from January or AprilJanuary to December0 since the beginning of the UNIX era is related to the return value of time () and the value used for date () similar to the system, with typical values of-2147483648-2147483647
Examples of the use of the getdate () function are as follows:
Copy plain text copy
The print result of the above procedure is as follows:
At this point, the study on "how to query the current time by php" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.