我正在使用 codeigniter 开发应用程序。在我的应用程序中,我想计算存储在数据库中的内容的时间段。例如 facebook 在浏览器中显示上传的时间。有没有办法使用codeigniter来做到这一点?
2 回答
If you've got direct access to the database in question, add a TIMESTAMP column to the table which contains the data you'd like to associate with a time. Use the 'DEFAULT CURRENT_TIMESTAMP' during table creation to have the new column store the time the data was initially inserted, and use the 'ON UPDATE CURRENT_TIMESTAMP' during table creation to have the column's timestamp automatically updated when the data gets modified. See here
I don't use codeigniter but I think you can do this, in your database you create a date/hour field and in your script you simply use your system date to know the difference in hours, days or whatever you want to use to display.
something like this :
function (diference) {
//all your sql traitement
$time_elapsed = $system_date - $your_sql_result
echo $time_elapsed;
}
And you can even do this with an SQL line too.