最后,我使用ci date helper并在
system/core/controller.php文件
或者您可以创建自己的控制器来继承ci_控制器,如
//system/core/Controller.php
class CI_Controller {
function __construct() {
parent::__construct();
}
public function oracle_date($timestamp='')
{
$this->load->helper('date');
if($timestamp=='date'){
$datestring = '%d-%M-%Y';
}
else
{
$datestring = '%d-%M-%Y %h.%i.%s %a';
}
$time = time();
$timestamp = strtoupper(mdate($datestring, $time));
return $timestamp;
}
}
//OR
//application/core
class MY_Controller extends CI_Controller {
function __construct() {
parent::__construct();
}
public function oracle_date($timestamp='')
{
$this->load->helper('date');
if($timestamp=='date'){
$datestring = '%d-%M-%Y';
}
else
{
$datestring = '%d-%M-%Y %h.%i.%s %a';
}
$time = time();
$timestamp = strtoupper(mdate($datestring, $time));
return $timestamp;
}
}
//Then use as follows:
//application/controllers
class User extends MY_Controller {
public function __construct(){
parent::__construct();
}
$timestamp = $this->oracle_date('timestamp'); //if parameter is 'date' it will return only date like DD-MM-YY and 'timestamp' it will return full timestamp
}
//OR
//application/controllers
class User extends CI_Controller {
public function __construct(){
parent::__construct();
}
$timestamp = $this->oracle_date('timestamp'); //if parameter is 'date' it will return only date like DD-MM-YY and 'timestamp' it will return full timestamp
}
如果创建自定义控制器,还可以将config.php文件中的前缀my更改为$config['subclass_prefix']='my_u';将$config['subclass_prefix']='your_u';