Home  >  Article  >  Backend Development  >  PHP series learning date function_PHP tutorial

PHP series learning date function_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 10:58:51852browse

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445660.htmlTechArticleIntroduction PHP is a very amazing language. It is powerful enough (the core language of the largest blog (wordpress)), it is broad enough (running on the largest social networking site facebook), it is enough...
Statement:
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