PHP time

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-28 08:27:26
Original
1335 people have browsed it

When using date and time, one disadvantage is that the time cannot be adjusted according to the time zone. Starting from PHP5.2, you can use the datetime class for construction. Its construction method requires two parameters, the first is the timestamp, and the other is Time zone (datetimezone).

<code><span><span><?php</span><span>//可以从服务器获取时区信息</span><span>$timeZone</span> =  ini_get(<span>'date.timezone'</span>);
<span>$dtz</span> = <span>new</span> DateTimeZone(<span>$timeZone</span>);
<span>//可以使用now表示当前时间</span><span>$dt</span> = <span>new</span> DateTime(<span>"now"</span>,<span>$dtz</span>);
<span>//format进行格式化时间</span><span>echo</span><span>"data : "</span>.<span>$dt</span>->format(<span>"Y-m-d  h:i:s"</span>);</span></span></code>
Copy after login
<code><span>//同样也可以使用diff()获得两个时间的时间差</span><span>$start_time</span><span>=</span><span>new</span> DateTime(<span>"2016-7-9 22:00:00"</span>,<span>$dtz</span>);
<span>$difference</span><span>=</span><span>$start_time</span><span>-></span>diff(<span>$dt</span>);
echo <span>$difference</span><span>-></span>format(<span>'%y-%m-%d %h:%i:%s'</span>);
<span>//</span><span>data</span> : <span>2016</span><span>-</span><span>07</span><span>-</span><span>10</span><span>12</span>:<span>55</span>:<span>36</span><span>0</span><span>-</span><span>0</span><span>-</span><span>0</span><span>2</span>:<span>55</span>:<span>36</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 the time of PHP, 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