time_since() php function
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.
精彩评论