0

我有以下代码:

$query = $this->EE->db->select('*')->where('form_name', 'Newsletter')->get('freeform_entries');
        $filename = "newsletter.csv";
        $path = "some/path";
        $delimiter = ",";
        $newline = "\r\n";
        $csv_data = $this->EE->dbutil->csv_from_result($query, $delimiter, $newline);

但是其中一个字段是时间戳,我需要将其转换为日期时间,以便在输出到 csv 时就是它的外观。所以我需要 20-10-13 09:28 而不是 1357752502

有任何想法吗?

4

1 回答 1

2

FROM_UNIXTIME将 unix_timestamp 参数的表示形式返回为 'YYYY-MM-DD HH:MM:SS' 中的值:

$query = $this->EE->db->select('FROM_UNIXTIME(timestamp_field) AS "value"', ... )->where('form_name', 'Newsletter')->get('freeform_entries');
        $filename = "newsletter.csv";
        $path = "some/path";
        $delimiter = ",";
        $newline = "\r\n";
        $csv_data = $this->EE->dbutil->csv_from_result($query, $delimiter, $newline);

更多信息:http ://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_from-unixtime

于 2013-01-25T11:45:51.297 回答