Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How php converts string to date format

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "how php converts string to date format". In daily operation, I believe many people have doubts about how php converts string to date format. Xiaobian 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 of "how php converts string to date format". Next, please follow the editor to study!

The method of converting to date format: 1, use the "strtotime ($string)" statement to convert the date-time text of the specified string type into a timest 2, use the "date (" Y-m-d H:i:s ", timestamp)" statement to format the timestamp into a "year-month-day hour: minutes: seconds" date format.

Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

Php converts string to date format

Implementation method:

Use strtotime () to extract the time and date from the string and parse the date-time description of the English text description into a UNIX timestamp

Date () formats the timestamp and converts it to a date in the specified format

Example:

Description:

The special characters that can be recognized in the date () first parameter format string are shown in the following table:

The character describes the day of the returned value example d month, using two digits to indicate, if less than two digits, the abbreviations from 001 to 31D days (using three letters) Mon to Sunl (lowercase letters of "L") the English words Sunday to SaturdayN according to the ISO-8601 standard format. Use a number to denote the day of the week (PHP5.1.0 plus) 1 (for Monday) to 7 (for Sunday) the English suffix (using 2 characters) after the number of days per month in S (using 2 characters) st, nd, rd, or th. You can use a number with j to represent the day of the week 0 (for Sunday) to 6 (for Saturday) z use a number to represent the day of the year 0 to 365W according to the ISO-8601 standard format, use a number to represent the week of the year, each week begins on Monday, (added in PHP 4.1.0) for example: 42 (week 42 of the year) F month English words For example, January or JuneJanuary to Decemberm use two digits to represent the current month 01 to 12m month abbreviations Jan to Decn use numbers to represent the current month 1 to 12t the number of days in a specified month 28 to 31L whether the specified year is a leap year if it is a leap year the value is 1, otherwise use a number to represent the year according to the ISO-8601 standard format This is the same as Y (PHP 5.1.0 add) 1999 or 2019Y uses four digits to represent a complete year for example: 1999 or 2019y uses two digits for example: 99 or 03a morning and afternoon values am or pmA uppercase morning and afternoon values AM or PMBSwatch Internet standard hours 000g to 999g hours 1 to 12G hours to 12G hours to hours 0 to 23 hours hours to hours Leading zero 01 to 12H uses a 24-hour format to represent hours, leading zero to 23i uses two digits to represent minutes, leading zero to 59 > s uses two digits to represent seconds, and leading zero to 59 > u milliseconds (added in PHP 5.2.2). It should be noted that the date () function always returns 000000 because it only accepts the integer parameter, while DateTime::format () supports milliseconds for example: 654321e time zone identification such as: UTC, GMT, Atlantic/AzoresI (uppercase "I") is daylight saving time 1, otherwise it is the number of hours between 0 and GMT, for example: + 0200p and Greenwich time (Greenwich mean time) Hours and minutes are separated by colons. For example, the time zone in which the local machine is located: EST, MDT (full text format under windows, such as "Eastern Standard Time", the Chinese version will display "China Standard time") the number of seconds of Z moveout offset, the time zone offset on the west side of UTC is always negative. The time zone offset on the east side of UTC is always positive-43200 to date in 43200cISO-8601 format 2014-02-12T15:19:21+00:00rRFC 822 for example: Thu,21 Dec 2000 16:01:07 + 0200U the number of seconds since the UNIX era (January 1 1970 00:00:00 GMT) and the same timestamp returned by time ()

Expand knowledge:

In PHP, date and time are obtained through date and time functions. The date and time functions depend on the time setting of the server. The default time setting of the server is Greenwich time (00:00 zone time). If the time is not set to a specific time zone, the time in the zero time zone obtained by the PHP function is 8 hours less than Beijing time.

In PHP, you can use the ini_set () function to set the value of the specified configuration option, which maintains the new value when the script runs and is restored at the end of the script. The syntax format of the function is as follows:

Ini_set ($varname, $newvalue)

Where $varname is the configuration option to be modified, and $newvalue is the new value of the configuration option.

Tip: the ini_set () function does not modify all configuration options. You can view the configuration options that can be modified by visiting "https://www.php.net/manual/zh/ini.list.php"".

At this point, the study on "how php converts string to date format" 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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report