In-depth study of PHP date function date()_PHP tutorial

WBOY
Release: 2016-07-15 13:27:28
Original
864 people have browsed it

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>
Copy after login

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>
Copy after login

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>
Copy after login

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>
Copy after login

The lowercase g represents the 12-hour clock without leading 0, while the lowercase h represents the 12-hour clock with leading 0. When using the 12-hour clock, it is necessary to indicate morning and afternoon. Lowercase a represents lowercase "am" and "pm", and uppercase A represents uppercase "AM" and "PM". A capital G represents the hour in the 24-hour format, but without a leading; use a capital H to represent the hour in the 24-hour format with a leading. Summary: The letter g represents the hour without a leading, and the letter h represents the hour with a leading; lowercase g and h represent the 12-hour clock, and capital G and H represent the 24-hour clock. The above is an introduction to the simple PHP date function year-month-day, hour:minute:second. I hope it will be helpful to everyone.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446513.htmlTechArticleThe format of dates is often difficult to control in programming. PHP date functions are quite commonly used, so I did some research. PHP date function, I will share it with you here, I hope it will be helpful to everyone...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template