Date format is often difficult to control in programming. PHP date function is quite commonly used, so I studied the PHP date function and shared it with you here. I hope it will be useful to everyone. PHP's date and time function date()
1, year-month-day
<ol class="dp-xml"> <li class="alt"><span><span>echo date('Y-m-j'); </span></span></li> <li class=""><span>2007-02-6 </span></li> <li class="alt"><span> </span></li> <li class=""><span>echo date('y-n-j'); </span></li> <li class="alt"><span>07-2-6 </span></li> </ol>
uppercase Y represents the four-digit year, while lowercase y represents the year. Two digits; lowercase m represents the number of the month (with a leading), while lowercase n represents the number of the month without the leading.
<ol class="dp-xml"> <li class="alt"><span><span>echo date('Y-M-j'); </span></span></li> <li class=""><span>2007-Feb-6 </span></li> <li class="alt"><span> </span></li> <li class=""><span>echo date('Y-m-d'); </span></li> <li class="alt"><span>2007-02-06 </span></li> </ol>
Capital M represents the 3 abbreviation characters of the month, while lowercase m represents the number of the month (with leading 0); there is no uppercase J, only lowercase j represents the date of the month, without leading o; If a leading month is required, use a lowercase d.
<ol class="dp-xml"> <li class="alt"><span><span>echo date('Y-M-j'); </span></span></li> <li class=""><span>2007-Feb-6 </span></li> <li class="alt"><span> </span></li> <li class=""><span>echo date('Y-F-jS'); </span></li> <li class="alt"><span>2007-February-6th </span></li> </ol>
Capital M represents the 3 abbreviated characters of the month, while capital F represents the full English version of the month. (No lowercase f) Capital S represents date suffixes, such as "st", "nd", "rd" and "th", depending on the date number. Summary: You can use uppercase Y and lowercase y to express the year; you can use uppercase F, uppercase M, lowercase m, and lowercase n to express the month (two ways of representing characters and numbers respectively); you can use lowercase d and lowercase j to express the day. A capital S represents the suffix of the date.
2, hour:minute:second
By default, PHP interprets the displayed time as "Greenwich Mean Time", which is different from our local The time difference is 8 hours.
<ol class="dp-xml"> <li class="alt"><span><span>echo date('g:i:s a'); </span></span></li> <li class=""><span>5:56:57 am </span></li> <li class="alt"><span> </span></li> <li class=""><span>echo date('h:i:s A'); </span></li> <li class="alt"><span>05:56:57 AM </span></li> </ol>