Summary of common methods for displaying php time, and summary for displaying php _ PHP Tutorial

Source: Internet
Author: User
Summary of common php display time methods, and summary of php display. Php display time common method summary, php display summary this article describes examples of php display time commonly used methods. Share it with you for your reference. The specific analysis is as follows: 1. Summary of common methods of PHP display time obtained by php function Date (), and summary of php display

This article describes common methods for displaying php time. Share it with you for your reference. The specific analysis is as follows:

I. PHP function Date () to get the current time

Code:
The code is as follows: <? Php echo $ showtime = date ("Y-m-d H: I: s");?>

Format: year-month-day hour: minute: Second

Related parameters:

A: "am" or "pm"
A: "AM" or "PM"
D: The number of two digits in a few days. if the number is less than two, the first digit is set to zero, for example, "01" to "31"
D: The day of the week. There are three English letters, for example, "Fri"
F: Month, full English name, for example, "January"
H: Hour in 12-hour format, for example, "01" to "12"
H: Hour in 24-hour format, for example, "00" to "23"
G: the hour in 12-hour format. less than two hours do not fill in zero, for example, "1" to 12"
G: the hour in the 24-hour format. less than two do not make up zero, for example, "0" to "23"
I: minutes, for example: "00" to "59"
J: The number of two digits in a few days. if there are less than two digits, do not add zero, for example, "1" to "31"
L: The day of the week. Full English name, for example, "Friday"
M: month, two digits. if there are less than two digits, add zero in front. for example, "01" to "12"
N: month, two digits. if less than two digits are left blank, for example, "1" to "12"
M: month, with three English letters, for example, "Jan"
S: seconds; for example: "00" to "59"
S: the end of the word is followed by an English sequence, with two English letters, such as "th" and "nd"
T: specifies the number of days in a month. for example, "28" to "31"
U: total number of seconds
W: number of weeks, for example, "0" (Sunday) to "6" (Saturday)
Y: year, four digits, for example, "1999"
Y: year, two digits, for example, "99"
Z: The day of the year. for example, "0" to "365"

II. solution to the eight-hour time difference obtained by the Date () function in PHP5

You only need to add a definition before the output Time: date_default_timezone_set ("PRC");, code:

<?phpdate_default_timezone_set("PRC");echo date("Y-m-d H:i:s");?>

3. PHP functions for obtaining the file creation time and last modification time

Filemtime (string filename): the time when the file was last modified. If an error occurs, false is returned. Time is returned in Unix timestamp format and can be used for Date ().

Filectime (string filename): the time when the last inode of the file was modified. If an error occurs, false is returned. Time is returned in Unix timestamp format.

Fileatime (string filename): the time when the object was last accessed. If an error occurs, false is returned. Time is returned in Unix timestamp format.

4. PHP compares the days of two different dates

Code:

<?phpecho (strtotime("2008-08-24 00:00:00")-strtotime("2008-08-08 00:00:00"))/86400;?>

I hope this article will help you with php programming.

Examples in this article describes common php display time methods. Share it with you for your reference. The specific analysis is as follows: 1. Date () of the PHP function is obtained...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.