指导我将日期更改为小时前[重复]

This question already has an answer here:

I have a website letting users posts on a wall and their posts are being submitted by date, I will post a picture. I took the the date script from GitHub, it's showing posted at 2018-12-03 02:12:33 (example), and I don't know how to change it to for example to 4h ago, 20 minutes ago etc... How can I achieve that?

My comment_list.php

      <?php
    require_once ("db.php");
    $memberId = 1;
    $sql = "SELECT
 tbl_comment.*,tbl_like_unlike.like_unlike FROM tbl_comment LEFT JOIN tbl_like_unlike ON tbl_comment.comment_id = tbl_like_unlike.comment_id AND member_id = " . $memberId . " ORDER BY tbl_like_unlike.like_unlike DESC, tbl_comment.date DESC";

    $result = mysqli_query($conn, $sql);
    $record_set = array();
    while ($row = mysqli_fetch_assoc($result)) {
        array_push($record_set, $row);
    }
    mysqli_free_result($result);

    mysqli_close($conn);
    echo json_encode($record_set);
    ?>

Database structure

    --
    -- Table structure for table `tbl_comment`
    --

    CREATE TABLE `tbl_comment` (
      `comment_id` int(11) NOT NULL,
      `parent_comment_id` int(11) DEFAULT NULL,
      `comment` varchar(200) NOT NULL,
      `comment_sender_name` varchar(40) NOT NULL,
      `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Table structure for table `tbl_like_unlike`
--

CREATE TABLE `tbl_like_unlike` (
  `id` int(11) NOT NULL,
  `member_id` int(11) NOT NULL,
  `comment_id` int(11) NOT NULL,
  `like_unlike` int(2) NOT NULL,
  `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

My comment_add.php

<?php
require_once ("db.php");
$commentId = isset($_POST['comment_id']) ? $_POST['comment_id'] : "";
$comment = isset($_POST['comment']) ? $_POST['comment'] : "";
$commentSenderName = isset($_POST['name']) ? $_POST['name'] : "";
$date = date('Y-m-d H:i:s');

I've read all similar questions here but coulnd't help myself, hope you could guide me. So is there a easy way changing it? Any help will mean a lot, thanks!

How date displays on my posts

</div>

The easiest way to do this is to use Carbon. Checkout this link https://carbon.nesbot.com/docs/. The Carbon class is inherited directly from PHP DateTime Class. For example,

<?php
require 'path/to/Carbon/autoload.php';
use Carbon\Carbon;

//Create instance of Carbon
$date = new Carbon('2018-09-01 03:25:17');

//Then use diffForHumans()
echo $date->diffForHumans();

//Result: 3 months ago