错误的日期格式codeigniter

时间:2014-10-05 07:19:15

标签: php codeigniter

当我从数据库中获取日期时,显示 2014-09-27 05:06:14

我应该显示日期 27-09-2014 05:06:14

在我的配置文件夹中,我将默认时区设置为

date_default_timezone_set('Australia/Queensland');

在我的模型或控制器中,可以将日期部分更改为我所追求的内容。

模型

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Users_model extends CI_Model {

    public function getUsers() {
        $this->db->select('user_id');
        $this->db->select('username');
        $this->db->select('date_added');
        $this->db->select('status');
        $this->db->from('user');
        $this->db->limit(20);
        $this->db->order_by('username', 'asc');
        $query_user = $this->db->get();
        if ($query_user->num_rows) {
            return $query_user->result_array();
            return true;
        } else {
            return false;
        }
    }
}

控制器功能

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Users extends MX_Controller {

    public function __construct() {
        parent::__construct();
        $this->lang->load('admin/user/users', 'english');
        $this->load->model('admin/user/users_model');
        if ($this->session->userdata('isLogged')) {
            return true;
        } else {
            redirect('admin');
        }
    }

    public function index() {
        $this->document->setTitle($this->lang->line('heading_title'));
        $this->getList();
    }

    private function getList() {

        $data['heading_title'] = $this->lang->line('heading_title');

        // Get Bread Crumbs

        $data['breadcrumbs'] = array();

        $data['breadcrumbs'][] = array(
            'text' => '<i class="fa fa-home"></i>' .' '.  $this->lang->line('text_home'),
            'href' => site_url('admin/dashboard')
        );

        $data['breadcrumbs'][] = array(
            'text'      => $this->lang->line('heading_title'),
            'href'      => site_url('admin/users')
        );

        // Get DB Results

        $data['users'] = array();

        $results = $this->users_model->getUsers();

        foreach ($results as $result) {
            $data['users'][] = array(
                'user_id' => $result['user_id'],
                'username' => $result['username'],
                'date_added' => $result['date_added'],
                'status' => ($result['status'] ? $this->lang->line('text_enabled') : $this->lang->line('text_disabled')),
                'edit' => site_url('admin/users/edit/' . $result['user_id']),
                'delete' => site_url('admin/users/delete/' . $result['user_id'])
            );
        }

        // Set Data

        $data['column_username'] =$this->lang->line('column_username');
        $data['column_status'] =$this->lang->line('column_status');
        $data['column_date_added'] =$this->lang->line('column_date_added');
        $data['column_action'] =$this->lang->line('column_action');

        if (trim($this->input->post('selected'))) {
            $data['selected'] = (array)$this->input->post('selected');
        } else {
            $data['selected'] = array();
        }

        return $this->load->view('user/users', $data);

    }

}

1 个答案:

答案 0 :(得分:0)

试试这个:

'date_added' => date('d-M-Y H:i:s', strtotime($result['date_added'])),