开发者

time_since() php function

开发者 https://www.devze.com 2023-02-24 10:36 出处:网络
开发者_运维百科do i need to include something to use time_since() function in php 5 or is has it been replace?It doesn\'t look like that function ever existed in PHP. Do you mean time() ?
开发者_运维百科

do i need to include something to use time_since() function in php 5 or is has it been replace?


It doesn't look like that function ever existed in PHP. Do you mean time() ?

However, you can get the time since an event like so...

$timeSince = time() - strtodate('last Saturday');

You can also use the object DateTime.

$now = new DateTime();

$timeSince = $now->diff(new DateTime('last Saturday'), TRUE);

Note that diff() method wasn't introduced until PHP 5.3.


PHP working out time since the post

If you're using PHP 5.3 or newer, you can take advantage of the new Date and Time classes added to PHP.

Specifically, DateTime has a diff method that returns a DateInterval class, which you can then format.

0

精彩评论

暂无评论...
验证码 换一张
取 消