In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly shows you "how to get time in PHP", which is easy to understand and clear. I hope it can help you solve your doubts. Let the editor lead you to study and learn this article "how to get time in PHP".
In the date and time functions in PHP, to get the current time, we need to know what a UNIX timestamp is.
The UNIX timestamp represents the total number of milliseconds since 00:00:00 (GMT) on January 1, 1970. Here are some functions that can get the current time.
Time () function
The time () function is the easiest function to get the current time, and it returns the UNIX timestamp of the current time. Examples are as follows:
When I run the function around 10:50 on October 21, 2021, the output is as follows:
Mktime () function
The mktime () function can return not only the UNIX timestamp of the current time, but also the UNIX timestamp of the specified time. Its syntax format is as follows:
Mktime (specified time, specified time minutes, specified time seconds, specified time month, specified time day, specified time year)
The parameters of this function can be omitted from right to left, and any omitted parameters will be set to the current value of the date and time of the cost.
Get the UNIX timestamp of the current time. The example is as follows:
Output result:
Get the UNIX timestamp for the specified time. The example is as follows:
Output result:
Gmmktime () function
The gmmktime () function can also get the UNIX timestamp of the GMT date, and its syntax format is as follows:
Gmmktime (specified time, specified time minutes, specified time seconds, specified time month, specified time day, specified time year)
Like mktime, it can be omitted from right to left, and any omitted parameter is set to the current value of the cost date.
Examples are as follows:
Output result:
As you can see from the above example, when all parameters are omitted, the parameters are set to the parameters of the current time in the current time zone, so the UNIX timestamp of the current time is output.
Output result:
As you can see from the above example, the UNIX timestamp for a specified time can be obtained through the gmmktime () function.
Microtime () function
The microtime () function returns the number of microseconds of the current UNIX timestamp, and its syntax is as follows:
Microtime ($get_as_float)
Examples are as follows:
Output result:
As you can see from the above example, the number of microseconds can be output through the microtime function, but the format of the output is the previous microsecond portion of the current UNIX timestamp, followed by the number of seconds of the current UNIX timestamp.
Although the microtime function can display a more delicate number of microseconds, but it does not look good, is there any way to see the number of microseconds intuitively?
We can set the parameter after the microtime function to true through the parameter setting after the function, and a floating-point string will be returned to represent the time.
Examples are as follows:
Output result:
As can be seen from the above example, the current time can be returned more intuitively by setting the parameters behind the function.
Getdate () function
We have previously introduced that so many functions can get the UNIX timestamp of the current time or the specified time, the getdate function is more powerful, it can get date and time information. Its syntax format is as follows:
Array getdate ([int $timestamp = time ()])
To put it simply, the getdate function can return an associative array based on the information of the parameters, which contains many elements. Here's a list:
Seconds--- represents the number of seconds
Minutes--- represents the number of minutes
Hours--- represents the number of hours
Mday--- indicates the number of the day of the month
The number of the day of the week in wday
Mon--- indicates the number of the month ordinal of the month
The full year of year--- in 4 digits
Yday--- represents the number of days of the year.
Weekday--- represents what day of the week in English
Month--- indicates the month in English
0Murray-indicates the number of seconds since the beginning of the UNIX era
Examples are as follows:
Output result:
As you can see from the above example, the returned array contains information about the current time through the getdate function.
The above is all the contents of the article "how to get time in PHP". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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.