Home > php教程 > php手册 > body text

讲解PHP函数Date()的相关运用

WBOY
Release: 2016-06-13 11:05:59
Original
1341 people have browsed it

我们要想在编写一、PHP函数Date()获取当前时间

代码:

<ol class="dp-xml"><li class="alt"><span><strong><font color="#006699"><span class="tag"></span><span class="tag-name">php</span></font></strong><span> echo $</span><span class="attribute"><font color="#ff0000">showtime</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">date</font></span><span>("Y-m-d H:i:s");</span><span class="tag"><strong><font color="#006699">?></font></strong></span><span> </span></span></li></ol>
Copy after login

显示的格式: 年-月-日 小时:分钟:秒

二、PHP5中PHP函数Date()获取时间相差8小时问题的解决方法

只需在输出时间之前加个定义:date_default_timezone_set("PRC");,代码:

<ol class="dp-xml">
<li class="alt"><span><strong><font color="#006699"><span class="tag"></span><span class="tag-name">php</span></font></strong><span>   </span></span></li>
<li class=""><span>date_default_timezone_set("PRC");   </span></li>
<li class="alt"><span>echo date("Y-m-d H:i:s");   </span></li>
<li class="">
<span></span><span class="tag"><strong><font color="#006699">?></font></strong></span><span>  </span>
</li>
</ol>
Copy after login

以上就是我们所介绍的关于PHP函数Date()的相关知识,希望对大家有所帮助。


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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template