Home >Backend Development >PHP Tutorial >PHP series learning date function_PHP tutorial
Introduction
PHP is a very amazing language. It is powerful enough (the core language of the largest blog (WordPress)), it is widespread enough (runs on Facebook, the largest social networking site), and it is simple enough (as the preferred introductory language for beginners). Works well on low-cost machines. Moreover, the PHP language has many very good server packages (such as WAMP and MAMP), which are very convenient to install on your machine. PHP has very rich library resources, making it easy for developers to handle some businesses. Since we have the most contact with dates in the project, we will start learning from the date function today.
Give a simple date example
I will use the echo command to output the content to our client (browser). I will use the following code as the base code.
<ol class="dp-xml"> <li class="alt"><span><span><!DOCTYPE html</span><span class="tag">></span><span> </span></span></li> <li> <span class="tag"><</span><span class="tag-name">html</span><span> </span><span class="attribute">lang</span><span>=</span><span class="attribute-value">"en"</span><span class="tag">></span><span> </span> </li> <li class="alt"> <span class="tag"><</span><span class="tag-name">head</span><span class="tag">></span><span> </span> </li> <li> <span> </span><span class="tag"><</span><span class="tag-name">meta</span><span> </span><span class="attribute">charset</span><span>=</span><span class="attribute-value">"utf-8"</span><span> </span><span class="tag">/></span><span> </span> </li> <li class="alt"> <span> </span><span class="tag"><</span><span class="tag-name">title</span><span class="tag">></span><span>Getting started with dates in php5</span><span class="tag"></</span><span class="tag-name">title</span><span class="tag">></span><span> </span> </li> <li> <span class="tag"></</span><span class="tag-name">head</span><span class="tag">></span><span> </span> </li> <li class="alt"> <span class="tag"><</span><span class="tag-name">body</span><span class="tag">></span><span> </span> </li> <li> <span class="tag"><?</span><span class="tag-name">php</span><span> </span></li><li class="alt"><span>date_default_timezone_set('Asia/Shanghai'); </span></li><li><span>echo "Today is ",date('l'); </span></li><li class="alt"><span class="tag">?></span><span> </span> </li> <li> <span class="tag"></</span><span class="tag-name">body</span><span class="tag">></span><span> </span> </li> <li class="alt"> <span class="tag"></</span><span class="tag-name">html</span><span class="tag">></span><span> </span> </li> </ol>
You will see the following content in your browser.
Today is Friday
This function outputs the text format of the day of the week. The date function requires at least one character parameter (this parameter tells us how to format the current date).
Try different formats
If you read the php manual