Home > Backend Development > PHP Tutorial > PHP---Date time

PHP---Date time

WBOY
Release: 2016-07-29 09:04:03
Original
1160 people have browsed it

Get the current Unix timestamp

from 1970.1.1 (00:00:00) - the number of seconds of the current time and

get the current date

date();

date(timestamp format, Specify timestamp [default is the current date and time, optional])

<code><span>//date函数,第二个参数取默认值的情况</span><span>echo</span> date(<span>"Y-m-d"</span>);<span>//2014-03-30</span><span>//date函数,第二个参数有值的情况</span><span>echo</span> date(<span>"Y-m-d"</span>,<span>'1396193923'</span>);<span>//2014-03-30,1396193923表示2014-03-30的unix时间戳</span></code>
Copy after login

Get the timestamp of the date

strtotime();

<code><span>strtotime(<span>"2016-02-05"</span>)</span>;
<span>strtotime(<span>"2016-2-5"</span>)</span>; <span>//测试也可行</span></code>
Copy after login

Convert the formatted date string into Unix timestamp

<code><span>strtotime(<span>"now"</span>)</span>;

<span>strtotime(<span>"+1 seconds"</span>)</span>;

<span>strtotime(<span>"+1 day"</span>)</span>;

<span>strtotime(<span>"+1 week"</span>)</span>;

<span>strtotime(<span>"+1 week 3 days 7 hours 5 seconds"</span>)</span>;
</code>
Copy after login

format Greenwich Mean Time (GMT)

<code><span>// gmdate() </span><span>//Y-m-d H:i:s</span><span>date_default_timezone_set(<span>"Asia/Shanghai"</span>)</span>;

echo <span>date(<span>'Y-m-d H:i:s'</span>, <span>time()</span>)</span>;

echo <span>gmdate(<span>'Y-m-d H:i:s'</span>, <span>time()</span>)</span>;</code>
Copy after login
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above has introduced PHP---Date and Time, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.

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