Home >Backend Development >PHP Tutorial >Expert guidance on how to get the day of the week in PHP_PHP Tutorial
I have been learning PHP for a long time, and I would like to share my experience with you. PHP is a server-side scripting language used to create dynamic WEB pages. Like ASP and ColdFusion, users can use a mixture of PHP and HTML to write WEB pages. When a visitor browses to the page, the server will first process the PHP commands in the page, and then transmit the processed results together with the HTML content to Access browser.
But unlike ASP or ColdFusion, PHP is an open source program with good cross-platform compatibility. Users can run PHP on Windows NT systems and many versions of Unix systems, and can run PHP as a built-in module of the Apache server or as a CGI program. In addition to being able to precisely control the display content of WEB pages, users can also send HTTP headers by using PHP. Users can set cookies through PHP, manage user identification, and redirect users' browsing pages. PHP has very powerful database support functions and can access almost all currently popular database systems. In addition, PHP can be integrated with multiple external libraries to provide users with more practical functions, such as generating PDF files.
<ol class="dp-xml"> <li class="alt"><span><span>date("l"); </span></span></li> <li class=""><span>//data就可以获取英文的星期比如Sunday </span></li> <li class="alt"><span>date("w"); </span></li> <li class=""><span>//这个可以获取数字星期比如123,注意0是星期日 </span></li> </ol>
Getting the Chinese day of the week can be done like this
<ol class="dp-xml"> <li class="alt"><span><span>$</span><span class="attribute"><font color="#ff0000">weekarray</font></span><span>=array("日","一","二","三","四","五","六"); </span></span></li> <li class=""><span>echo "星期".$weekarray[date("w")]; </span></li> </ol>
Getting the specified date is:
<ol class="dp-xml"> <li class="alt"><span><span>$</span><span class="attribute"><font color="#ff0000">weekarray</font></span><span>=array("日","一","二","三","四","五","六"); </span></span></li> <li class=""><span>echo "星期".$weekarray[date("w","2011-11-11")]; </span></li> </ol>
Because The date function is very powerful. It can handle all such tasks. I have attached a table in the manual
<ol class="dp-xml"> <li class="alt"><span><span>a - "am" 或是 "pm" </span></span></li> <li class=""><span>A - "AM" 或是 "PM" </span></li> <li class="alt"><span>d - 几日,二位数字,若不足二位则前面补零; 如: "01" 至 "31" </span></li> <li class=""><span>D - 星期几,三个英文字母; 如: "Fri" </span></li> <li class="alt"><span>F - 月份,英文全名; 如: "January" </span></li> <li class=""><span>h - 12 小时制的小时; 如: "01" 至 "12" </span></li> <li class="alt"><span>H - 24 小时制的小时; 如: "00" 至 "23" </span></li> <li class=""><span>g - 12 小时制的小时,不足二位不补零; 如: "1" 至 12" </span></li> <li class="alt"><span>G - 24 小时制的小时,不足二位不补零; 如: "0" 至 "23" </span></li> <li class=""><span>i - 分钟; 如: "00" 至 "59" </span></li> <li class="alt"><span>j - 几日,二位数字,若不足二位不补零; 如: "1" 至 "31" </span></li> <li class=""><span>l - 星期几,英文全名; 如: "Friday" </span></li> <li class="alt"><span>m - 月份,二位数字,若不足二位则在前面补零; 如: "01" 至 "12" </span></li> <li class=""><span>n - 月份,二位数字,若不足二位则不补零; 如: "1" 至 "12" </span></li> <li class="alt"><span>M - 月份,三个英文字母; 如: "Jan" </span></li> <li class=""><span>s - 秒; 如: "00" 至 "59" </span></li> <li class="alt"><span>S - 字尾加英文序数,二个英文字母; 如: "th","nd" </span></li> <li class=""><span>t - 指定月份的天数; 如: "28" 至 "31" </span></li> <li class="alt"><span>U - 总秒数 </span></li> <li class=""><span>w - 数字型的星期几,如: "0" (星期日) 至 "6" (星期六) </span></li> <li class="alt"><span>Y - 年,四位数字; 如: "1999" </span></li> <li class=""><span>y - 年,二位数字; 如: "99" </span></li> <li class="alt"><span>z - 一年中的第几天; 如: "0" 至 "365" </span></li> </ol>
The above introduces in detail the method of getting the day of the week in PHP and the introduction of the date function. Come on, everyone. Give it a try.