This article illustrates the common method of displaying time in PHP. Share to everyone for your reference. The specific analysis is as follows:
A, PHP function date () Get the current time
The code is as follows: <?php Echo $showtime =date ("y-m-d h:i:s");? >
displayed in the format: year-month-day hours: minutes: sec
Related parameters:
A: "AM" or "PM"
A: "AM" or "PM"
D: A few days, two digits, if less than two digits before 0, such as: "01" to "31"
D: Day of the week, three English letters, such as: "Fri"
F: Month, full name in English, such as: "January"
H:12 hours, such as: "01" to "12"
H: 24 Hours of hours, such as: "00" to "23"
G:12 hours, less than two-digit 0, such as: "1" to 12 "
G: 24 Hours of the hour, less than two digits do not fill 0, such as: "0" to "23"
I: minutes, such as: "00" to "59"
J: A few days, two digits, if less than two digits do not fill 0, such as: "1" to "31"
L: Day of the week, full name in English, such as: "Friday"
M: month, two digits, if less than two digits in front of 0; such as: "01" to "12"
N: month, two digits, if less than two digits, do not fill 0, such as: "1" to "12"
M: Month, three English letters;
s: seconds; such as: "00" to "59"
S: The end of the word plus English ordinal number, two English letters, such as: "th", "nd"
T: Specify the number of days of the month; for example: "28" to "31"
U: The total number of seconds
W: Number of days of the week, such as: "0" (Sunday) to "6" (Saturday)
Y: year, four digits; for example: "1999"
Y: Year, two digits; for example: "99"
Z: The first day of the year; For example: "0" to "365"
A solution to the 8-hour difference in the date () function in PHP5
Just add a definition before the output time: Date_default_timezone_set ("PRC");, Code:
?
1 2 3 4 |
<?php date_default_timezone_set ("PRC"); echo Date ("y-m-d h:i:s");?> |
Third, PHP to obtain the file creation time and the last modification time function
Filemtime (string filename): Returns the time when the file was last modified, false when an error occurred. Time is returned as a Unix timestamp and can be used for date ().
Filectime (string filename): Returns the time when the last inode was modified, or False if an error occurred. Time is returned in the form of a Unix timestamp.
Fileatime (string filename): Returns the time the file was last accessed, or False if an error occurred. Time is returned in the form of a Unix timestamp.
Four, PHP comparison two date difference days
Code:
?
1 2 3 |
<?php Echo (Strtotime ("2008-08-24 00:00:00")-strtotime ("2008-08-08 00:00:00"))/86400;?> |
I hope this article will help you with your PHP program design.