In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
Most people do not understand the knowledge points of this article "php has no way to operate time", so the editor summarizes the following contents, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "php has no way to operate time" article.
Php has a method of operating time. Php provides a wealth of date-time processing methods: 1, date (), format the local date and time; 2, mktime (), return the date timest 3, idate (), format the local time to an integer; 4, strtotime (), convert the time string into a timestamp, and so on.
Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
Php has a method of operating time.
The use and processing of date and time is essential in Web development, such as the time when the form is submitted, the time the user logs in, and the time when the data in the database is updated and deleted. If you want to record when these operations are performed, you need to do so by date and time.
PHP provides us with rich date-time processing functions:
The function describes the checkdate () verification Gregory date. Date_add () adds a day, month, year, hour, minute, and second to a date. Date_create_from_format () returns a new DateTime object formatted according to the specified format. Date_create () returns a new DateTime object. Date_date_set () sets a new date. Date_default_timezone_get () returns the default time zone and is used by all Date/Time functions. Date_default_timezone_set () sets the default time zone, which is used by all Date/Time functions. Date_diff () returns the difference between two days. Date_format () returns the date formatted according to the specified format. Date_get_last_errors () returns a warning / error in the date string. Date_interval_create_from_date_string () builds a DateInterval from the relevant part of the string. Date_interval_format () formats the interval. Date_isodate_set () sets the ISO date. Date_modify () modifies the timestamp. Date_offset_get () returns the time zone offset. Date_parse_from_format () returns an associative array with the details of the specified date based on the specified format. Date_parse () returns an associative array with details for the specified date. Date_sub () subtracts the day, month, year, hour, minute, and second from the specified date. Date_sun_info () returns an array of information about sunrise / sunset and the beginning / end of dusk at the specified date and place. Date_sunrise () returns the sunrise time of the specified date and place. Date_sunset () returns the sunset time of the specified date and place. Date_time_set () sets the time. Date_timestamp_get () returns the Unix timestamp. Date_timestamp_set () sets the date and time based on the Unix timestamp. Date_timezone_get () returns the time zone of a given DateTime object. Date_timezone_set () sets the time zone of the DateTime object. Date () formats the local date and time. Getdate () returns date / time information for a timestamp or current local date / time. Gettimeofday () returns the current time. Gmdate () formats the GMT/UTC date and time. Gmmktime () returns the UNIX timestamp of the GMT date. Gmstrftime () formats the GMT/UTC date and time according to the locale. Idate () formats the local time / date as an integer. Localtime () returns the local time. Microtime () returns the number of microseconds of the current Unix timestamp. Mktime () returns the Unix timestamp of a date. Strftime () formats the local time / date according to the locale. Strptime () parses the time / date generated by strftime (). Strtotime () parses the date or time description of any English text into a Unix timestamp. Time () returns the Unix timestamp of the current time. Timezone_abbreviations_list () returns an associative array of daylight saving time, offset, and time zone names. Timezone_identifiers_list () returns a numeric array with all the time zone identifiers. Timezone_location_get () returns the location information for the specified time zone. Timezone_name_from_ abbr () returns the time zone name based on the time zone acronym. Timezone_name_get () returns the name of the time zone. Timezone_offset_get () returns the time zone offset from GMT. Timezone_open () creates a new DateTimeZone object. Timezone_transitions_get () returns all transformations for the time zone. Timezone_version_get () returns the version of the time zone database.
Here is a brief introduction to some time and date processing methods:
1. PHP gets the current time (5 ways)
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.
Gmmktime ()
The gmmktime () function gets the UNIX timestamp of the GMT date. The syntax is as follows:
Int gmmktime ([int $hour [, int $minute [, int $second [, int $month [, int $day [, int $year [, int $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:
The print result of executing the above program is:
1467909956 1467852303
Mktime ()
Mktime () can also get a UNIX timestamp for a date. The syntax is as follows:
Int mktime ([int $hour = date ("H") [, int $minute = date ("I") [, int $second = date ("s") [, int $month = date ("n") [, int $day = date ("j") [, int $year = date ("Y") [, int $is_dst =-1])
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:
The print result of executing the above program is:
1467910465 1467852303
Microtime ()
Microtime () gets the current UNIX timestamp and number of microseconds. The syntax is as follows:
Mixed microtime ([bool $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:
The print result of the above procedure is as follows:
0.40474900 14679108621467910862.4048
Time ()
The time () function returns the current UNIX timestamp. The syntax is as follows:
Int time (void)
The syntax of the time () function is relatively simple, and the examples are as follows:
The print result of executing the above program is:
1467911104
Getdate ()
Getdate () can get the date and time information. The syntax is as follows:
Array getdate ([int $timestamp = time ()])
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:
The print result of the above procedure is as follows:
Array (11) {["seconds"] = > int (57) ["minutes"] = > int (18) ["hours"] = > int (17) ["mday"] = > int (7) ["wday"] = > int (4) ["mon"] = > int (7) ["year"] = > int (2016) ["yday"] = > int (2016) ["weekday"] = > string (8) "Thursday" ["month"] = > string (4) "July" [0] = > int (1467911937)}
2. Strtotime () and mktime (): date to time stamp
Strtotime () function
Using the strtotime () function, you can convert any type of string date / time to a UNIX timestamp in the following syntax format:
Strtotime ($time [, $now = time ()])
Where $time is a string representing a time / date, such as "2020-01-01"; $now is an optional parameter that is used to calculate the timestamp of the return value. The function returns the specified string if it succeeds, and FALSE if it fails.
It is also important to note that if two digits are used to represent the year, 0-69 represents 2000-2069 and 1970-2000.
[example] use the strtotime () function to get the timestamp of the specified time.
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.