1, year-month-day
Echo date ('Y-m-J ');
2007-02-6
Echo date ('Y-n-J ');
07-2-6
Uppercase Y indicates four digits of the year, while lowercase y indicates two digits of the year;
Lowercase m indicates the number of the month (with the leading digit), while lowercase n indicates the number of the month without the leading digit.
Echo date ('Y-M-J ');
2007-Feb-6
Echo date ('Y-m-D ');
2007-02-06
Uppercase M indicates the three abbreviations of the month, while lowercase m indicates the number of the month (with leading 0 );
There is no upper-case J. Only lower-case j indicates the date of the month, and there is no leading o. If the month needs to have the upper-case J, the lower-case d is used.
Echo date ('Y-M-J ');
2007-Feb-6
Echo date ('Y-F-js ');
2007-February-6th
Uppercase M indicates the three abbreviated characters of the month, while uppercase F indicates the full English writing of the month. (No lower case f)
Uppercase S indicates the suffix of a date, such as "st", "nd", "rd", and "th". For details, see the date number.
Summary:
Y indicates that the year can be in uppercase or lowercase y;
Indicates that the month can be written in uppercase letters (F), uppercase letters (M), lowercase letters (m), and lowercase letters (n );
Indicates the date suffix.
2, hour: minute: Second
By default, PHP interprets the display time as "Greenwich Mean Time", which is 8 hours different from our local time.
Echo date ('G: I: s ');
5:56:57 am
Echo date ('H: I: s ');
05:56:57 AM
Lowercase g indicates the 12-hour system, with no leading 0, while lowercase h indicates the 12-hour system with leading 0.
When the 12-hour format is used, it indicates that upper afternoon, lower case a indicates lower case "am" and "pm", and upper case A indicates upper case "AM" and "PM ".
Echo date ('G: I: s ');
14:02:26
Uppercase G indicates the number of hours in the 24-hour format, but does not contain the leading value. Uppercase H indicates the number of hours in the 24-hour format.
Summary:
The letter g indicates that the hour does not contain a leading character, and the letter h indicates that the hour contains a leading character;
Lowercase g and h are in 12-hour format, while uppercase G and H are in 24-hour format.
3, leap year, week, day
Echo date ('L ');
This year's leap year: 0
Echo date ('L ');
Today is: Tuesday
Echo date ('D ');
Today is: Tue
Capital L indicates whether to determine the leap year of the year. If it is true, 1 is returned; otherwise, 0 is returned;
Lowercase l indicates the day of the week in full (Tuesday );
However, uppercase D is used to represent the three abbreviation of the day of the week (Tue ).
Echo date ('w ');
Today's week: 2
Echo date ('w ');
This week is the 06th week of the year.
Lowercase w indicates the day of the week, expressed in numbers
In upper case, W indicates the number of weeks in a year.
Echo date ('t ');
This month is 28 days
Echo date ('Z ');
Today is the 36th day of this year
Lowercase t indicates the number of days in the current month
Lowercase z indicates that today is the day of the year
Converts a daytime date to a timestamp.
Strtotime (time, now) parameter description
Time specifies the time string to be parsed.
Now is used to calculate the timestamp of the returned value. If this parameter is omitted, the current time is used.
<? Php
Echo strtotime ("now"), "n ";
Echo strtotime ("10 September 2000"), "n ";
Echo strtotime ("+ 1 day"), "n ";
Echo strtotime ("+ 1 week"), "n ";
Echo strtotime ("+ 1 week 2 days 4 hours 2 seconds"), "n ";
Echo strtotime ("next Thursday"), "n ";
Echo strtotime ("last Monday"), "n ";
?>
<? Php
$ Str = 'not Good ';
// Previous to PHP 5.1.0 you wowould compare with-1, instead of false
If ($ timestamp = strtotime ($ str) === false ){
Echo "The string ($ str) is bogus ";
} Else {
Echo "$ str =". date ('l dS of f y h: I: s A', $ timestamp );
}
?>
Let's look at the strtotime instance.
*/
Echo strtotime ('2014-2-14 '), "<br/> ";
Echo date ('Y-m-D', strtotime ('2017-2-14 '));
// Output value
1266076800
2010-02-14
// You should be in strtotime () and you decide what to do. For example
<? Php
# On 2/8/2010
Date ('m/d/Y', strtotime ('First Day'); #02/01/10
Date ('m/d/Y', strtotime ('last day'); #02/28/10
Date ('m/d/Y', strtotime ('last day next month'); #03/31/10
Date ('m/d/Y', strtotime ('last day last month'); #01/31/10
Date ('m/d/Y', strtotime ('2017-12 last day ')); #12/31/09-this doesn't work if you reverse the order of the year and month
Date ('m/d/Y', strtotime ('2017-03 last day'); #2009/09
Date ('m/d/Y', strtotime ('2017-03'); #2009/09
Date ('m/d/Y', strtotime ('Last day of march 100'); #2009/09
Date ('m/d/Y', strtotime ('Last day of March'); #03/31/10
?>
More related functions
Date_default_timezone_set ('prc'); // Default time zone
$ T = time ();
$ Today = date ("Y-m-d", time ());
Echo "today: $ today <br/> ";
Echo "one day:". date ("Y-m-d", strtotime ("18 June 2008"). "<br/> ";
Echo "yesterday:". date ("Y-m-d", strtotime ("-1 day"). "<br/> ";
Echo "tomorrow:". date ("Y-m-d", strtotime ("+ 1 day"). "<br/> ";
Echo "one week later:". date ("Y-m-d", strtotime ("+ 1 week"). "<br/> ";
Echo "one week, two days, four hours, two seconds later :". date ("Y-m-d G: H: s", strtotime ("+ 1 week 2 days 4 hours 2 seconds ")). "<br/> ";
Echo "next Thursday:". date ("Y-m-d", strtotime ("next Thursday"). "<br/> ";
Echo "last Monday:". date ("Y-m-d", strtotime ("last Monday"). "<br/> ";
Echo "a month ago:". date ("Y-m-d", strtotime ("last month"). "<br/> ";
Echo "one month later:". date ("Y-m-d", strtotime ("+ 1 month"). "<br/> ";
Echo "10 years later:". date ("Y-m-d", strtotime ("+ 10 year"). "<br/> ";
Echo "<br/> ======================================== ==================================< br/> <br/> ";
$ W = date ("w", time (); // Obtain the week number of the week.
Echo "today is $ w <br/> ";
$ D = array ("day", "one", "two", "three", "four", "five", "six ");
$ Whatday = "week". $ d [date ("w", strtotime ($ today)]; // Obtain the day of the week
Echo "today is $ whatday <br/> ";
$ D0 = date ("Y-m-d", strtotime ("-$ w day", $ t); // week start
Echo "this week's Sunday is: $ d0 <br/> ";
$ D6 = date ("Y-m-d", strtotime (6-$ w). "day", $ t); // end of the week
Echo "Saturday this week: $ d6 <br/> ";
Echo "Sunday of this week:". date ("Y-m-d", strtotime ("Sunday"). "<br/>"; // start of the week
Echo "Saturday this week is:". date ("Y-m-d", strtotime ("Saturday"). "<br/>"; // The end of the week
Echo "last week is Sunday:". date ("Y-m-d", strtotime ("last Sunday"). "<br/>"; // start last week
Echo "last week is:". date ("Y-m-d", strtotime ("last Saturday"). "<br/>"; // last week ends
Echo "<br/> ======================================== ==================================< br/> <br/> ";
$ Time = abs (strtotime ("2012-12-21")-strtotime (date ("Y-m-d")/86400); // get the number of days difference between two dates
Echo "from the end of the world: $ time <br/>"; // The end of last week