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)06/03 Report--
This article introduces the relevant knowledge of "how to format time and date in PHP". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
In PHP, we can use UNIX as the standard format for timestamps, but it is not easy to read, and a string is not in line with our reading habits. At this point, we need to format the UNIX timestamp into the way we are used to reading, and the format can also be changed into the format required by other software.
Date () time date format
In PHP, we have the date () function to format a time or date, and its function syntax format is as follows:
Date (formatted time format, timestamp to be formatted)
The formatted time format can be represented by characters with special meanings. Examples are as follows:
DMeltel-indicates the day of the month, which should be expressed as two digits. If it is less than two digits, it should be preceded by a zero.
Today is the 21st, output result:
Dmurmuri-an abbreviation for the day of the week in English.
Today is Thursday, output the results:
Fmurmure-English word for month
Today is October, output results:
There are many special characters, some of which are listed below:
Tmurmuri-the number of days of the specified month 28 to 31
The acronym Jan to Dec
NMMI-use numbers to indicate the current month from 1 to 12
GMMI-use the 12-hour format to represent the number of hours 1 to 12
Gmurmuri-use 24-hour format to represent hours 0 to 23
Zmurmuri-use numbers to indicate the days 0 to 365 of the year
MMMI-use two-digit numbers to represent the current month 01 to 12
Smurmuri-use two digits to represent seconds, with leading zero to 59 >
IMurray-use two digits to represent minutes, with leading zero to 59 >
Hmurmuri-represents hours in a 12-hour format, with leading zeros 01 to 12
Hmurmuri-hours are expressed in 24-hour format, with leading zero to 23
Nmurmuri-use numbers to indicate the day of the week, where 1 is Monday and 7 is Sunday.
Wmurmuri-use numbers to indicate the day of the week 0 (for Sunday) to 6 (for Saturday)
It can be combined, as shown in the following example:
Output result:
From the example above, we know that time can be formatted with different parameters in the date function.
Next, let's learn how to calculate the time difference through PHP, which can be used as an extension of knowledge.
PHP calculation time difference
During the development process, you may encounter situations such as how long the user has been created, how long it has been logging on the site, or calculating birthdays. When this happens, we need to calculate the time difference between the two times.
In PHP, we can calculate the time difference by converting two dates into timestamps, using the mktime function we talked about in the previous article. (click here "Summary of ways to get time in PHP (detailed examples)" to see the use of the mktime function in the previous article.
Examples are as follows:
Output result:
In this way, we have completed how to calculate the time difference between two times.
That's all for the content of "how to format time and date in PHP". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.