Home  >  Article  >  php教程  >  PHP系列学习之日期函数

PHP系列学习之日期函数

WBOY
WBOYOriginal
2016-06-13 11:15:13935browse

介绍

PHP是一门非常令人惊奇的语言。它足够强大(最大的博客(wordpress)的核心语言),它足够广泛(运行在最大社交网站facebook上),它足够简单(作为初学者首选入门语言)。在低成本的机器上运行良好。而且php语言有很多非常不错的服务器套件(如WAMP和MAMP),很方便的安装在你的机器上。PHP有非常丰富的库资源,便于开发者很容易的处理一些业务。由于我们在项目中与日期接触最多,所以今天就从日期函数入手学习。

举一个简单的date例子

我将使用echo命令把内容输出到我们的客户端(浏览器)。我将使用下面的代码做为基础代码。

<ol class="dp-xml">
<li class="alt"><span><span>nbsp;html</span><span class="tag">></span><span> </span></span></li>
<li><span class="tag"><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></span></li>
<li class="alt"><span class="tag"><span class="tag-name">head</span><span class="tag">></span><span> </span></span></li>
<li>
<span>    </span><span class="tag"><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></span>
</li>
<li class="alt">
<span>    </span><span class="tag"><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></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 class="tag-name">body</span><span class="tag">></span><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>

你将在你的浏览器里看到如下的内容。

Today is Friday 

这个函数输出星期几的文本格式。date函数至少需要一个字符参数(这个参数告诉我们怎样格式化当前日期)。

尝试不同的格式

如果你看了php手册中

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
Previous article:并行的RPC框架Next article:Spring双数据库配置