Example: obtain the date of the previous day from January 1,.
| The code is as follows: |
Copy code |
|
<? Php
// Convert a time point to a timestamp
$ Date = strtotime ('2017-5-1 ');
// Output the date before the day, minus the number of seconds of the day in the timestamp
Echo date ('Y-m-D', $ date-1*24*60*60 );
?> |
Output: 2012-4-30
In addition, the time () function obtains the timestamp of the current date!
Let's look at another instance.
| The code is as follows: |
Copy code |
|
<? PHP
$ Date_1 = "& Prime; // The format can also be: $ Date_1 =" 23:29:14 & Prime ;;
$ Date_2 = "2009-10-1 & Prime ;;
$ Date_List_a1 = explode ("-", $ Date_1 );
$ Date_List_a2 = explode ("-", $ Date_2 );
$ D1 = mktime (0, 0, 0, $ Date_List_a1 [1], $ Date_List_a1 [2], $ Date_List_a1 [0]);
$ D2 = mktime (0, 0, 0, $ Date_List_a2 [1], $ Date_List_a2 [2], $ Date_List_a2 [0]);
$ Days = round ($ d1-$ d2)/3600/24 );
Echo "the difference between the two dates is $ Days ";
?> |
Time reference
| The code is as follows: |
Copy code |
|
<? Php echo $ showtime = date ("Y-m-d H: I: s");?> |
Display format: year-month-day hour: minute: wonderful
Related time parameters:
A-"am" or "pm"
A-"AM" or "PM"
D-a few days, two digits. If there are less than two digits, the first zero is added. For example, "01 & Prime; to" 31 & Prime;
D-the day of the week, with three English letters, for example, "Fri"
F-month, full English name, for example, "January"
H-12 hours; for example, "01 & Prime; to" 12 & Prime;
H-24 hours; for example, "00 & Prime; to" 23 & Prime;
For hours in the g-12 hour format, less than two do not fill in zero; for example: "1 & Prime; to 12 & Prime;
For hours in the G-24 hour system, less than two do not fill in zero; for example, "0 & Prime; to" 23 & Prime;
I-minutes; for example, "00 & Prime; to" 59 & Prime;
J-a few days, two digits. If less than two digits are left blank, for example, "1 & Prime; to" 31 & Prime;
L-the day of the week, full name in English; for example, "Friday"
M-month, two digits. If there are less than two digits, add zero in front. For example, "01 & Prime; to" 12 & Prime;
N-month, two digits. If less than two digits are left blank, for example, "1 & Prime; to" 12 & Prime;
M-month, with three English letters, for example, Jan"
S-seconds; for example, "00 & Prime; to" 59 & Prime;
The end of the S-character is followed by an English sequence number with two English letters, such as "th" and "nd"
T-specifies the number of days of the month. For example, "28 & Prime; to" 31 & Prime;
U-total seconds
W-number of weeks, for example, "0 & Prime; (Sunday) to" 6 & Prime; (Saturday)
Y-year, four digits, for example, "1999 & Prime;
Y-year, two digits, for example, "99 & Prime;
Z-the day of the year; for example, "0 & Prime; to" 365 & Prime;
You can freely set the displayed content, connection symbols, or display locations, such as date ("m-d H") or date ("dmY");?> And so on