0

我正在使用 codeigniter 开发应用程序。在我的应用程序中,我想计算存储在数据库中的内容的时间段。例如 facebook 在浏览器中显示上传的时间。有没有办法使用codeigniter来做到这一点?

4

2 回答 2

1

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

于 2012-08-23T23:19:46.683 回答
0

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.

于 2012-08-23T23:16:40.150 回答