时间戳使用“;“很久以前”;功能和日期差异


Time stamp using "time ago" function and date difference

我的主机让MySQL的工作变得异常困难;为了避免必须使用MySQL,有没有办法通过使用无表的"时间戳"函数,然后使用echo来显示当前日期和"时间戳之前"日期之间的差异,来为文章添加时间戳?

DATETIME列添加到文章表中。然后当你插入/更新文章时,你可以用设置时间

$row = array(
    'title' => 'My Article',
    ...
    'date' => date("Y-m-d H:i:s")
);
$db->insert('article', $row);

当你拿出文章时,你可以得到区别:

$row = $db->get('article', 32);
$diff = time() - strtotime($row['date']); 
print $diff . ' in seconds';

然后,你可以用秒$diff做一些事情,比如除以分钟、小时、天等。来显示你想要的时间类型。