<?php
session_start();
function time_stamp($session_time)
{
$session_time=new DateTime();
$post_time=new DateTime();
$time_difference = date_diff($post_time,$session_time);
$time_difference->format('y-m-d h-m-s');
$seconds = $time_difference ;
$minutes = round($time_difference / 60 ); //line 11
$hours = round($time_difference / 3600 ); //line 12
$days = round($time_difference / 86400 ); //line 13
$weeks = round($time_difference / 604800 ); //line 14
$months = round($time_difference / 2419200 ); //line 15
$years = round($time_difference / 29030400 ); //line 16
if($seconds <= 60)
{
echo"$seconds seconds ago"; //line 18
}
else if($minutes <=60)
{
if($minutes==1)
{
echo"one minute ago";
}
else
{
echo"$minutes minutes ago";
}
?>
** When I submit my post it should show x seconds/minutes etc ago
ERROR MESSAGE Notice: Object of class DateInterval could not be converted to int in C:\xampp\htdocs\social\home.php on line 11
Notice: Object of class DateInterval could not be converted to int in C:\xampp\htdocs\social\home.php on line 12
Notice: Object of class DateInterval could not be converted to int in C:\xampp\htdocs\social\home.php on line 13
Notice: Object of class DateInterval could not be converted to int in C:\xampp\htdocs\social\home.php on line 14
Notice: Object of class DateInterval could not be converted to int in C:\xampp\htdocs\social\home.php on line 15
Notice: Object of class DateInterval could not be converted to int in C:\xampp\htdocs\social\home.php on line 16
Notice: Object of class DateInterval could not be converted to int in C:\xampp\htdocs\social\home.php on line 18
Recoverable fatal error: Object of class DateInterval could not be converted to string in C:\xampp\htdocs\social\home.php on line 20 **
public DateInterval::format ( string $format ) : string
https://www.php.net/manual/en/dateinterval.format.php
The format function (line 10), will return a string , so I'm not sure why you're using that to get the $seconds
Instead, date_diff
returns a DateInterval object, so you should look at the php docs for DateInterval https://www.php.net/manual/en/class.dateinterval.php
And you may notice that it has some properties such as: $y
, $m
, etc. So what you should do is actually something like $time_difference->s
.
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加